1 | /* |
2 | * Copyright (C) 2013 Apple Inc. All rights reserved. |
3 | * |
4 | * Redistribution and use in source and binary forms, with or without |
5 | * modification, are permitted provided that the following conditions |
6 | * are met: |
7 | * 1. Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. |
9 | * 2. Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. |
12 | * |
13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
15 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
17 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
23 | * THE POSSIBILITY OF SUCH DAMAGE. |
24 | */ |
25 | |
26 | #include "config.h" |
27 | #include "InlineElementBox.h" |
28 | |
29 | #include "InlineFlowBox.h" |
30 | #include "PaintInfo.h" |
31 | #include "RenderBlock.h" |
32 | #include "RenderBox.h" |
33 | #include "RenderLineBreak.h" |
34 | #include <wtf/IsoMallocInlines.h> |
35 | |
36 | namespace WebCore { |
37 | |
38 | WTF_MAKE_ISO_ALLOCATED_IMPL(InlineElementBox); |
39 | |
40 | void InlineElementBox::deleteLine() |
41 | { |
42 | if (!extracted()) { |
43 | if (is<RenderBox>(renderer())) |
44 | downcast<RenderBox>(renderer()).setInlineBoxWrapper(nullptr); |
45 | else if (is<RenderLineBreak>(renderer())) |
46 | downcast<RenderLineBreak>(renderer()).setInlineBoxWrapper(nullptr); |
47 | } |
48 | delete this; |
49 | } |
50 | |
51 | void InlineElementBox::() |
52 | { |
53 | setExtracted(true); |
54 | if (is<RenderBox>(renderer())) |
55 | downcast<RenderBox>(renderer()).setInlineBoxWrapper(nullptr); |
56 | else if (is<RenderLineBreak>(renderer())) |
57 | downcast<RenderLineBreak>(renderer()).setInlineBoxWrapper(nullptr); |
58 | } |
59 | |
60 | void InlineElementBox::attachLine() |
61 | { |
62 | setExtracted(false); |
63 | if (is<RenderBox>(renderer())) |
64 | downcast<RenderBox>(renderer()).setInlineBoxWrapper(this); |
65 | else if (is<RenderLineBreak>(renderer())) |
66 | downcast<RenderLineBreak>(renderer()).setInlineBoxWrapper(this); |
67 | } |
68 | |
69 | void InlineElementBox::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset, LayoutUnit /* lineTop */, LayoutUnit /*lineBottom*/) |
70 | { |
71 | if (!paintInfo.shouldPaintWithinRoot(renderer())) |
72 | return; |
73 | |
74 | if (paintInfo.phase != PaintPhase::Foreground && paintInfo.phase != PaintPhase::Selection && paintInfo.phase != PaintPhase::EventRegion) |
75 | return; |
76 | |
77 | LayoutPoint childPoint = paintOffset; |
78 | if (is<RenderBox>(renderer()) && parent()->renderer().style().isFlippedBlocksWritingMode()) // Faster than calling containingBlock(). |
79 | childPoint = renderer().containingBlock()->flipForWritingModeForChild(&downcast<RenderBox>(renderer()), childPoint); |
80 | |
81 | renderer().paintAsInlineBlock(paintInfo, childPoint); |
82 | } |
83 | |
84 | bool InlineElementBox::nodeAtPoint(const HitTestRequest& request, HitTestResult& result, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, LayoutUnit /* lineTop */, LayoutUnit /*lineBottom*/, |
85 | HitTestAction) |
86 | { |
87 | // Hit test all phases of replaced elements atomically, as though the replaced element established its |
88 | // own stacking context. (See Appendix E.2, section 6.4 on inline block/table elements in the CSS2.1 |
89 | // specification.) |
90 | LayoutPoint childPoint = accumulatedOffset; |
91 | if (is<RenderBox>(renderer()) && parent()->renderer().style().isFlippedBlocksWritingMode()) // Faster than calling containingBlock(). |
92 | childPoint = renderer().containingBlock()->flipForWritingModeForChild(&downcast<RenderBox>(renderer()), childPoint); |
93 | |
94 | return renderer().hitTest(request, result, locationInContainer, childPoint); |
95 | } |
96 | |
97 | } |
98 | |