Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / rendering / RenderDetailsMarker.cpp
1 /*
2  * Copyright (C) 2010, 2011 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 #include "core/rendering/RenderDetailsMarker.h"
23
24 #include "core/HTMLNames.h"
25 #include "core/dom/Element.h"
26 #include "core/html/HTMLElement.h"
27 #include "core/paint/DetailsMarkerPainter.h"
28 #include "core/rendering/PaintInfo.h"
29
30 namespace blink {
31
32 using namespace HTMLNames;
33
34 RenderDetailsMarker::RenderDetailsMarker(Element* element)
35     : RenderBlockFlow(element)
36 {
37 }
38
39 RenderDetailsMarker::Orientation RenderDetailsMarker::orientation() const
40 {
41     switch (style()->writingMode()) {
42     case TopToBottomWritingMode:
43         if (style()->isLeftToRightDirection())
44             return isOpen() ? Down : Right;
45         return isOpen() ? Down : Left;
46     case RightToLeftWritingMode:
47         if (style()->isLeftToRightDirection())
48             return isOpen() ? Left : Down;
49         return isOpen() ? Left : Up;
50     case LeftToRightWritingMode:
51         if (style()->isLeftToRightDirection())
52             return isOpen() ? Right : Down;
53         return isOpen() ? Right : Up;
54     case BottomToTopWritingMode:
55         if (style()->isLeftToRightDirection())
56             return isOpen() ? Up : Right;
57         return isOpen() ? Up : Left;
58     }
59     return Right;
60 }
61
62 void RenderDetailsMarker::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
63 {
64     DetailsMarkerPainter(*this).paint(paintInfo, paintOffset);
65 }
66
67 bool RenderDetailsMarker::isOpen() const
68 {
69     for (RenderObject* renderer = parent(); renderer; renderer = renderer->parent()) {
70         if (!renderer->node())
71             continue;
72         if (isHTMLDetailsElement(*renderer->node()))
73             return !toElement(renderer->node())->getAttribute(openAttr).isNull();
74         if (isHTMLInputElement(*renderer->node()))
75             return true;
76     }
77
78     return false;
79 }
80
81 }