Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(526)

Side by Side Diff: sky/engine/core/rendering/RenderWidget.cpp

Issue 682263003: Remove RenderWidget. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sky/engine/core/rendering/RenderWidget.h ('k') | sky/engine/web/ChromeClientImpl.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2000 Dirk Mueller (mueller@kde.org)
4 * Copyright (C) 2004, 2006, 2009, 2010 Apple Inc. All rights reserved.
5 * Copyright (C) 2013 Google Inc. All rights reserved.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
16 *
17 * You should have received a copy of the GNU Library General Public License
18 * along with this library; see the file COPYING.LIB. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
21 *
22 */
23
24 #include "config.h"
25 #include "core/rendering/RenderWidget.h"
26
27 #include "core/frame/LocalFrame.h"
28 #include "core/rendering/GraphicsContextAnnotator.h"
29 #include "core/rendering/HitTestResult.h"
30 #include "core/rendering/RenderLayer.h"
31 #include "core/rendering/RenderView.h"
32 #include "core/rendering/compositing/CompositedLayerMapping.h"
33 #include "core/rendering/compositing/RenderLayerCompositor.h"
34 #include "wtf/HashMap.h"
35
36 namespace blink {
37
38 RenderWidget::RenderWidget(Element* element)
39 : RenderReplaced(element)
40 #if !ENABLE(OILPAN)
41 // Reference counting is used to prevent the widget from being
42 // destroyed while inside the Widget code, which might not be
43 // able to handle that.
44 , m_refCount(1)
45 #endif
46 {
47 ASSERT(element);
48 frameView()->addWidget(this);
49 }
50
51 void RenderWidget::willBeDestroyed()
52 {
53 frameView()->removeWidget(this);
54 RenderReplaced::willBeDestroyed();
55 }
56
57 void RenderWidget::destroy()
58 {
59 #if ENABLE(ASSERT) && ENABLE(OILPAN)
60 ASSERT(!m_didCallDestroy);
61 m_didCallDestroy = true;
62 #endif
63 willBeDestroyed();
64 clearNode();
65 #if ENABLE(OILPAN)
66 // In Oilpan, postDestroy doesn't delete |this|. So calling it here is safe
67 // though |this| will be referred in FrameView.
68 postDestroy();
69 #else
70 deref();
71 #endif
72 }
73
74 RenderWidget::~RenderWidget()
75 {
76 #if !ENABLE(OILPAN)
77 ASSERT(m_refCount <= 0);
78 #endif
79 }
80
81 Widget* RenderWidget::widget() const
82 {
83 return 0;
84 }
85
86 // Widgets are always placed on integer boundaries, so rounding the size is actu ally
87 // the desired behavior. This function is here because it's otherwise seldom wha t we
88 // want to do with a LayoutRect.
89 static inline IntRect roundedIntRect(const LayoutRect& rect)
90 {
91 return IntRect(roundedIntPoint(rect.location()), roundedIntSize(rect.size()) );
92 }
93
94 bool RenderWidget::setWidgetGeometry(const LayoutRect& frame)
95 {
96 if (!node())
97 return false;
98
99 Widget* widget = this->widget();
100 ASSERT(widget);
101
102 IntRect newFrame = roundedIntRect(frame);
103
104 if (widget->frameRect() == newFrame)
105 return false;
106
107 RefPtr<RenderWidget> protector(this);
108 RefPtr<Node> protectedNode(node());
109 widget->setFrameRect(newFrame);
110 return widget->frameRect().size() != newFrame.size();
111 }
112
113 bool RenderWidget::updateWidgetGeometry()
114 {
115 Widget* widget = this->widget();
116 ASSERT(widget);
117
118 LayoutRect contentBox = contentBoxRect();
119 LayoutRect absoluteContentBox(localToAbsoluteQuad(FloatQuad(contentBox)).bou ndingBox());
120 if (widget->isFrameView()) {
121 contentBox.setLocation(absoluteContentBox.location());
122 return setWidgetGeometry(contentBox);
123 }
124
125 return setWidgetGeometry(absoluteContentBox);
126 }
127
128 void RenderWidget::layout()
129 {
130 ASSERT(needsLayout());
131
132 clearNeedsLayout();
133 }
134
135 void RenderWidget::styleDidChange(StyleDifference diff, const RenderStyle* oldSt yle)
136 {
137 RenderReplaced::styleDidChange(diff, oldStyle);
138 }
139
140 void RenderWidget::paintContents(PaintInfo& paintInfo, const LayoutPoint& paintO ffset)
141 {
142 LayoutPoint adjustedPaintOffset = paintOffset + location();
143
144 Widget* widget = this->widget();
145 ASSERT(widget);
146
147 // Tell the widget to paint now. This is the only time the widget is allowed
148 // to paint itself. That way it will composite properly with z-indexed layer s.
149 IntPoint widgetLocation = widget->frameRect().location();
150 IntPoint paintLocation(roundToInt(adjustedPaintOffset.x() + borderLeft() + p addingLeft()),
151 roundToInt(adjustedPaintOffset.y() + borderTop() + paddingTop()));
152 IntRect paintRect = paintInfo.rect;
153
154 IntSize widgetPaintOffset = paintLocation - widgetLocation;
155 // When painting widgets into compositing layers, tx and ty are relative to the enclosing compositing layer,
156 // not the root. In this case, shift the CTM and adjust the paintRect to be root-relative to fix plug-in drawing.
157 if (!widgetPaintOffset.isZero()) {
158 paintInfo.context->translate(widgetPaintOffset.width(), widgetPaintOffse t.height());
159 paintRect.move(-widgetPaintOffset);
160 }
161 widget->paint(paintInfo.context, paintRect);
162
163 if (!widgetPaintOffset.isZero())
164 paintInfo.context->translate(-widgetPaintOffset.width(), -widgetPaintOff set.height());
165 }
166
167 void RenderWidget::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
168 {
169 ANNOTATE_GRAPHICS_CONTEXT(paintInfo, this);
170
171 if (!shouldPaint(paintInfo, paintOffset))
172 return;
173
174 LayoutPoint adjustedPaintOffset = paintOffset + location();
175
176 if (hasBoxDecorationBackground() && (paintInfo.phase == PaintPhaseForeground || paintInfo.phase == PaintPhaseSelection))
177 paintBoxDecorationBackground(paintInfo, adjustedPaintOffset);
178
179 if (paintInfo.phase == PaintPhaseMask) {
180 paintMask(paintInfo, adjustedPaintOffset);
181 return;
182 }
183
184 if ((paintInfo.phase == PaintPhaseOutline || paintInfo.phase == PaintPhaseSe lfOutline) && style()->hasOutline())
185 paintOutline(paintInfo, LayoutRect(adjustedPaintOffset, size()));
186
187 if (paintInfo.phase != PaintPhaseForeground)
188 return;
189
190 if (style()->hasBorderRadius()) {
191 LayoutRect borderRect = LayoutRect(adjustedPaintOffset, size());
192
193 if (borderRect.isEmpty())
194 return;
195
196 // Push a clip if we have a border radius, since we want to round the fo reground content that gets painted.
197 paintInfo.context->save();
198 RoundedRect roundedInnerRect = style()->getRoundedInnerBorderFor(borderR ect,
199 paddingTop() + borderTop(), paddingBottom() + borderBottom(), paddin gLeft() + borderLeft(), paddingRight() + borderRight(), true, true);
200 clipRoundedInnerRect(paintInfo.context, borderRect, roundedInnerRect);
201 }
202
203 Widget* widget = this->widget();
204 if (widget)
205 paintContents(paintInfo, paintOffset);
206
207 if (style()->hasBorderRadius())
208 paintInfo.context->restore();
209
210 // Paint a partially transparent wash over selected widgets.
211 if (isSelected()) {
212 LayoutRect rect = localSelectionRect();
213 rect.moveBy(adjustedPaintOffset);
214 paintInfo.context->fillRect(pixelSnappedIntRect(rect), selectionBackgrou ndColor());
215 }
216
217 if (canResize())
218 layer()->scrollableArea()->paintResizer(paintInfo.context, roundedIntPoi nt(adjustedPaintOffset), paintInfo.rect);
219 }
220
221 #if !ENABLE(OILPAN)
222 void RenderWidget::deref()
223 {
224 if (--m_refCount <= 0)
225 postDestroy();
226 }
227 #endif
228
229 void RenderWidget::updateOnWidgetChange()
230 {
231 Widget* widget = this->widget();
232 if (!widget)
233 return;
234
235 if (!style())
236 return;
237
238 if (!needsLayout())
239 updateWidgetGeometry();
240 }
241
242 void RenderWidget::updateWidgetPosition()
243 {
244 Widget* widget = this->widget();
245 if (!widget || !node()) // Check the node in case destroy() has been called.
246 return;
247
248 bool boundsChanged = updateWidgetGeometry();
249
250 // if the frame bounds got changed, or if view needs layout (possibly indica ting
251 // content size is wrong) we have to do a layout to set the right widget siz e
252 if (widget && widget->isFrameView()) {
253 FrameView* frameView = toFrameView(widget);
254 // Check the frame's page to make sure that the frame isn't in the proce ss of being destroyed.
255 if ((boundsChanged || frameView->needsLayout()) && frameView->frame().pa ge())
256 frameView->layout();
257 }
258 }
259
260 void RenderWidget::widgetPositionsUpdated()
261 {
262 Widget* widget = this->widget();
263 if (!widget)
264 return;
265 widget->widgetPositionsUpdated();
266 }
267
268 bool RenderWidget::nodeAtPoint(const HitTestRequest& request, HitTestResult& res ult, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedO ffset, HitTestAction action)
269 {
270 bool hadResult = result.innerNode();
271 bool inside = RenderReplaced::nodeAtPoint(request, result, locationInContain er, accumulatedOffset, action);
272
273 // Check to see if we are really over the widget itself (and not just in the border/padding area).
274 if ((inside || result.isRectBasedTest()) && !hadResult && result.innerNode() == node())
275 result.setIsOverWidget(contentBoxRect().contains(result.localPoint()));
276 return inside;
277 }
278
279 CursorDirective RenderWidget::getCursor(const LayoutPoint& point, Cursor& cursor ) const
280 {
281 return RenderReplaced::getCursor(point, cursor);
282 }
283
284 } // namespace blink
OLDNEW
« no previous file with comments | « sky/engine/core/rendering/RenderWidget.h ('k') | sky/engine/web/ChromeClientImpl.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698