1 | /* |
2 | * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
3 | * |
4 | * This library is free software; you can redistribute it and/or |
5 | * modify it under the terms of the GNU Library General Public |
6 | * License as published by the Free Software Foundation; either |
7 | * version 2 of the License, or (at your option) any later version. |
8 | * |
9 | * This library is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | * Library General Public License for more details. |
13 | * |
14 | * You should have received a copy of the GNU Library General Public License |
15 | * along with this library; see the file COPYING.LIB. If not, write to |
16 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
17 | * Boston, MA 02110-1301, USA. |
18 | * |
19 | */ |
20 | |
21 | #include "config.h" |
22 | #if ENABLE(METER_ELEMENT) |
23 | #include "RenderMeter.h" |
24 | |
25 | #include "HTMLMeterElement.h" |
26 | #include "HTMLNames.h" |
27 | #include "RenderTheme.h" |
28 | #include <wtf/IsoMallocInlines.h> |
29 | |
30 | namespace WebCore { |
31 | |
32 | using namespace HTMLNames; |
33 | |
34 | WTF_MAKE_ISO_ALLOCATED_IMPL(RenderMeter); |
35 | |
36 | RenderMeter::RenderMeter(HTMLElement& element, RenderStyle&& style) |
37 | : RenderBlockFlow(element, WTFMove(style)) |
38 | { |
39 | } |
40 | |
41 | RenderMeter::~RenderMeter() = default; |
42 | |
43 | HTMLMeterElement* RenderMeter::meterElement() const |
44 | { |
45 | ASSERT(element()); |
46 | |
47 | if (is<HTMLMeterElement>(*element())) |
48 | return downcast<HTMLMeterElement>(element()); |
49 | |
50 | ASSERT(element()->shadowHost()); |
51 | return downcast<HTMLMeterElement>(element()->shadowHost()); |
52 | } |
53 | |
54 | void RenderMeter::updateLogicalWidth() |
55 | { |
56 | RenderBox::updateLogicalWidth(); |
57 | |
58 | IntSize frameSize = theme().meterSizeForBounds(*this, snappedIntRect(frameRect())); |
59 | setLogicalWidth(isHorizontalWritingMode() ? frameSize.width() : frameSize.height()); |
60 | } |
61 | |
62 | RenderBox::LogicalExtentComputedValues RenderMeter::computeLogicalHeight(LayoutUnit logicalHeight, LayoutUnit logicalTop) const |
63 | { |
64 | auto computedValues = RenderBox::computeLogicalHeight(logicalHeight, logicalTop); |
65 | LayoutRect frame = frameRect(); |
66 | if (isHorizontalWritingMode()) |
67 | frame.setHeight(computedValues.m_extent); |
68 | else |
69 | frame.setWidth(computedValues.m_extent); |
70 | IntSize frameSize = theme().meterSizeForBounds(*this, snappedIntRect(frame)); |
71 | computedValues.m_extent = isHorizontalWritingMode() ? frameSize.height() : frameSize.width(); |
72 | return computedValues; |
73 | } |
74 | |
75 | void RenderMeter::updateFromElement() |
76 | { |
77 | repaint(); |
78 | } |
79 | |
80 | } // namespace WebCore |
81 | |
82 | #endif |
83 | |