blob: c6b4b04056fe50b5d3dae0f93c0a44a09c346230 [file] [log] [blame]
yael.aharon@nokia.com666f4b82010-05-15 16:41:06 +00001/*
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"
tkent@chromium.orgc271a5f2013-02-08 09:34:13 +000022#if ENABLE(METER_ELEMENT)
yael.aharon@nokia.com666f4b82010-05-15 16:41:06 +000023#include "RenderMeter.h"
24
25#include "HTMLMeterElement.h"
darin@apple.comf5247d12010-06-13 17:29:10 +000026#include "HTMLNames.h"
yael.aharon@nokia.com666f4b82010-05-15 16:41:06 +000027#include "RenderTheme.h"
fpizlo@apple.comd03c5942017-11-07 19:21:52 +000028#include <wtf/IsoMallocInlines.h>
yael.aharon@nokia.com666f4b82010-05-15 16:41:06 +000029
yael.aharon@nokia.com666f4b82010-05-15 16:41:06 +000030namespace WebCore {
31
32using namespace HTMLNames;
33
fpizlo@apple.comd03c5942017-11-07 19:21:52 +000034WTF_MAKE_ISO_ALLOCATED_IMPL(RenderMeter);
35
antti@apple.com454418f2016-04-25 19:49:23 +000036RenderMeter::RenderMeter(HTMLElement& element, RenderStyle&& style)
aestes@apple.com13aae082016-01-02 08:03:08 +000037 : RenderBlockFlow(element, WTFMove(style))
yael.aharon@nokia.com666f4b82010-05-15 16:41:06 +000038{
39}
40
dbates@webkit.orgf21f3ae2017-10-19 23:48:45 +000041RenderMeter::~RenderMeter() = default;
morrita@google.com6509cd22010-06-18 05:13:19 +000042
shinyak@chromium.org037f1cd2012-08-15 09:37:32 +000043HTMLMeterElement* RenderMeter::meterElement() const
44{
antti@apple.com8f335082013-09-09 19:54:33 +000045 ASSERT(element());
shinyak@chromium.org037f1cd2012-08-15 09:37:32 +000046
cdumez@apple.coma9c60c92014-10-02 19:39:41 +000047 if (is<HTMLMeterElement>(*element()))
cdumez@apple.com72754ba2014-09-23 22:03:15 +000048 return downcast<HTMLMeterElement>(element());
shinyak@chromium.org037f1cd2012-08-15 09:37:32 +000049
antti@apple.com8f335082013-09-09 19:54:33 +000050 ASSERT(element()->shadowHost());
cdumez@apple.com72754ba2014-09-23 22:03:15 +000051 return downcast<HTMLMeterElement>(element()->shadowHost());
shinyak@chromium.org037f1cd2012-08-15 09:37:32 +000052}
53
tony@chromium.org5270e662012-09-10 21:47:50 +000054void RenderMeter::updateLogicalWidth()
morrita@google.coma70a8f42010-06-08 06:26:06 +000055{
tony@chromium.org5270e662012-09-10 21:47:50 +000056 RenderBox::updateLogicalWidth();
tony@chromium.org845cf6e2012-09-24 21:11:48 +000057
zalan@apple.com376339c2014-08-28 04:24:31 +000058 IntSize frameSize = theme().meterSizeForBounds(*this, snappedIntRect(frameRect()));
tony@chromium.org845cf6e2012-09-24 21:11:48 +000059 setLogicalWidth(isHorizontalWritingMode() ? frameSize.width() : frameSize.height());
morrita@google.coma70a8f42010-06-08 06:26:06 +000060}
61
zalan@apple.comcca4b692016-12-16 04:37:28 +000062RenderBox::LogicalExtentComputedValues RenderMeter::computeLogicalHeight(LayoutUnit logicalHeight, LayoutUnit logicalTop) const
morrita@google.coma70a8f42010-06-08 06:26:06 +000063{
zalan@apple.comcca4b692016-12-16 04:37:28 +000064 auto computedValues = RenderBox::computeLogicalHeight(logicalHeight, logicalTop);
tony@chromium.org845cf6e2012-09-24 21:11:48 +000065 LayoutRect frame = frameRect();
66 if (isHorizontalWritingMode())
67 frame.setHeight(computedValues.m_extent);
68 else
69 frame.setWidth(computedValues.m_extent);
zalan@apple.com376339c2014-08-28 04:24:31 +000070 IntSize frameSize = theme().meterSizeForBounds(*this, snappedIntRect(frame));
tony@chromium.org845cf6e2012-09-24 21:11:48 +000071 computedValues.m_extent = isHorizontalWritingMode() ? frameSize.height() : frameSize.width();
zalan@apple.comcca4b692016-12-16 04:37:28 +000072 return computedValues;
morrita@google.coma70a8f42010-06-08 06:26:06 +000073}
74
morrita@google.comf1987562011-09-21 05:41:27 +000075void RenderMeter::updateFromElement()
76{
77 repaint();
78}
79
yael.aharon@nokia.com666f4b82010-05-15 16:41:06 +000080} // namespace WebCore
darin@apple.comf5247d12010-06-13 17:29:10 +000081
yael.aharon@nokia.com666f4b82010-05-15 16:41:06 +000082#endif