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

Side by Side Diff: third_party/WebKit/Source/web/WebFrameWidgetImpl.cpp

Issue 2715243004: [blink] Support (semi-)transparent background colors in WebView/Frame. (Closed)
Patch Set: address comments Created 3 years, 9 months 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2014 Google Inc. All rights reserved. 2 * Copyright (C) 2014 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 12 matching lines...) Expand all
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "web/WebFrameWidgetImpl.h" 31 #include "web/WebFrameWidgetImpl.h"
32 32
33 #include <memory>
34
33 #include "core/dom/DocumentUserGestureToken.h" 35 #include "core/dom/DocumentUserGestureToken.h"
34 #include "core/editing/EditingUtilities.h" 36 #include "core/editing/EditingUtilities.h"
35 #include "core/editing/Editor.h" 37 #include "core/editing/Editor.h"
36 #include "core/editing/FrameSelection.h" 38 #include "core/editing/FrameSelection.h"
37 #include "core/editing/InputMethodController.h" 39 #include "core/editing/InputMethodController.h"
38 #include "core/editing/PlainTextRange.h" 40 #include "core/editing/PlainTextRange.h"
39 #include "core/frame/FrameHost.h" 41 #include "core/frame/FrameHost.h"
40 #include "core/frame/FrameView.h" 42 #include "core/frame/FrameView.h"
41 #include "core/frame/RemoteFrame.h" 43 #include "core/frame/RemoteFrame.h"
42 #include "core/frame/Settings.h" 44 #include "core/frame/Settings.h"
43 #include "core/frame/VisualViewport.h" 45 #include "core/frame/VisualViewport.h"
44 #include "core/html/HTMLTextAreaElement.h" 46 #include "core/html/HTMLTextAreaElement.h"
45 #include "core/input/EventHandler.h" 47 #include "core/input/EventHandler.h"
46 #include "core/layout/LayoutView.h" 48 #include "core/layout/LayoutView.h"
47 #include "core/layout/api/LayoutViewItem.h" 49 #include "core/layout/api/LayoutViewItem.h"
48 #include "core/layout/compositing/PaintLayerCompositor.h" 50 #include "core/layout/compositing/PaintLayerCompositor.h"
49 #include "core/page/ContextMenuController.h" 51 #include "core/page/ContextMenuController.h"
50 #include "core/page/FocusController.h" 52 #include "core/page/FocusController.h"
51 #include "core/page/Page.h" 53 #include "core/page/Page.h"
52 #include "core/page/PointerLockController.h" 54 #include "core/page/PointerLockController.h"
53 #include "platform/KeyboardCodes.h" 55 #include "platform/KeyboardCodes.h"
54 #include "platform/WebFrameScheduler.h" 56 #include "platform/WebFrameScheduler.h"
55 #include "platform/animation/CompositorAnimationHost.h" 57 #include "platform/animation/CompositorAnimationHost.h"
58 #include "platform/graphics/Color.h"
56 #include "platform/graphics/CompositorMutatorClient.h" 59 #include "platform/graphics/CompositorMutatorClient.h"
57 #include "public/web/WebAutofillClient.h" 60 #include "public/web/WebAutofillClient.h"
58 #include "public/web/WebPlugin.h" 61 #include "public/web/WebPlugin.h"
59 #include "public/web/WebRange.h" 62 #include "public/web/WebRange.h"
60 #include "public/web/WebWidgetClient.h" 63 #include "public/web/WebWidgetClient.h"
61 #include "web/AnimationWorkletProxyClientImpl.h" 64 #include "web/AnimationWorkletProxyClientImpl.h"
62 #include "web/CompositionUnderlineVectorBuilder.h" 65 #include "web/CompositionUnderlineVectorBuilder.h"
63 #include "web/CompositorMutatorImpl.h" 66 #include "web/CompositorMutatorImpl.h"
64 #include "web/CompositorWorkerProxyClientImpl.h" 67 #include "web/CompositorWorkerProxyClientImpl.h"
65 #include "web/ContextMenuAllowedScope.h" 68 #include "web/ContextMenuAllowedScope.h"
66 #include "web/InspectorOverlay.h" 69 #include "web/InspectorOverlay.h"
67 #include "web/PageOverlay.h" 70 #include "web/PageOverlay.h"
68 #include "web/WebDevToolsAgentImpl.h" 71 #include "web/WebDevToolsAgentImpl.h"
69 #include "web/WebInputEventConversion.h" 72 #include "web/WebInputEventConversion.h"
70 #include "web/WebInputMethodControllerImpl.h" 73 #include "web/WebInputMethodControllerImpl.h"
71 #include "web/WebLocalFrameImpl.h" 74 #include "web/WebLocalFrameImpl.h"
72 #include "web/WebPluginContainerImpl.h" 75 #include "web/WebPluginContainerImpl.h"
73 #include "web/WebRemoteFrameImpl.h" 76 #include "web/WebRemoteFrameImpl.h"
74 #include "web/WebViewFrameWidget.h" 77 #include "web/WebViewFrameWidget.h"
75 #include "wtf/AutoReset.h" 78 #include "wtf/AutoReset.h"
76 #include "wtf/PtrUtil.h" 79 #include "wtf/PtrUtil.h"
77 #include <memory>
78 80
79 namespace blink { 81 namespace blink {
80 82
81 // WebFrameWidget ------------------------------------------------------------ 83 // WebFrameWidget ------------------------------------------------------------
82 84
83 WebFrameWidget* WebFrameWidget::create(WebWidgetClient* client, 85 WebFrameWidget* WebFrameWidget::create(WebWidgetClient* client,
84 WebLocalFrame* localRoot) { 86 WebLocalFrame* localRoot) {
85 // Pass the WebFrameWidget's self-reference to the caller. 87 // Pass the WebFrameWidget's self-reference to the caller.
86 return WebFrameWidgetImpl::create(client, localRoot); 88 return WebFrameWidgetImpl::create(client, localRoot);
87 } 89 }
(...skipping 16 matching lines...) Expand all
104 WebLocalFrame* localRoot) 106 WebLocalFrame* localRoot)
105 : m_client(client), 107 : m_client(client),
106 m_localRoot(toWebLocalFrameImpl(localRoot)), 108 m_localRoot(toWebLocalFrameImpl(localRoot)),
107 m_mutator(nullptr), 109 m_mutator(nullptr),
108 m_layerTreeView(nullptr), 110 m_layerTreeView(nullptr),
109 m_rootLayer(nullptr), 111 m_rootLayer(nullptr),
110 m_rootGraphicsLayer(nullptr), 112 m_rootGraphicsLayer(nullptr),
111 m_isAcceleratedCompositingActive(false), 113 m_isAcceleratedCompositingActive(false),
112 m_layerTreeViewClosed(false), 114 m_layerTreeViewClosed(false),
113 m_suppressNextKeypressEvent(false), 115 m_suppressNextKeypressEvent(false),
114 m_isTransparent(false), 116 m_backgroundColorOverrideEnabled(false),
117 m_backgroundColorOverride(Color::transparent),
118 m_baseBackgroundColorOverrideEnabled(false),
119 m_baseBackgroundColorOverride(Color::transparent),
115 m_imeAcceptEvents(true), 120 m_imeAcceptEvents(true),
116 m_selfKeepAlive(this) { 121 m_selfKeepAlive(this) {
117 DCHECK(m_localRoot->frame()->isLocalRoot()); 122 DCHECK(m_localRoot->frame()->isLocalRoot());
118 initializeLayerTreeView(); 123 initializeLayerTreeView();
119 m_localRoot->setFrameWidget(this); 124 m_localRoot->setFrameWidget(this);
120 125
121 if (localRoot->parent()) 126 if (localRoot->parent())
122 setIsTransparent(true); 127 setBackgroundColorOverride(Color::transparent);
123 } 128 }
124 129
125 WebFrameWidgetImpl::~WebFrameWidgetImpl() {} 130 WebFrameWidgetImpl::~WebFrameWidgetImpl() {}
126 131
127 DEFINE_TRACE(WebFrameWidgetImpl) { 132 DEFINE_TRACE(WebFrameWidgetImpl) {
128 visitor->trace(m_localRoot); 133 visitor->trace(m_localRoot);
129 visitor->trace(m_mouseCaptureNode); 134 visitor->trace(m_mouseCaptureNode);
130 } 135 }
131 136
132 // WebWidget ------------------------------------------------------------------ 137 // WebWidget ------------------------------------------------------------------
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 // Pass the limits even though this is for subframes, as the limits will be 265 // Pass the limits even though this is for subframes, as the limits will be
261 // needed in setting the raster scale. 266 // needed in setting the raster scale.
262 m_layerTreeView->setPageScaleFactorAndLimits( 267 m_layerTreeView->setPageScaleFactorAndLimits(
263 1, view()->minimumPageScaleFactor(), view()->maximumPageScaleFactor()); 268 1, view()->minimumPageScaleFactor(), view()->maximumPageScaleFactor());
264 } 269 }
265 270
266 void WebFrameWidgetImpl::updateLayerTreeBackgroundColor() { 271 void WebFrameWidgetImpl::updateLayerTreeBackgroundColor() {
267 if (!m_layerTreeView) 272 if (!m_layerTreeView)
268 return; 273 return;
269 274
270 m_layerTreeView->setBackgroundColor(backgroundColor()); 275 WebColor color = backgroundColor();
276 m_layerTreeView->setBackgroundColor(color);
271 } 277 }
272 278
273 void WebFrameWidgetImpl::updateLayerTreeDeviceScaleFactor() { 279 void WebFrameWidgetImpl::updateLayerTreeDeviceScaleFactor() {
274 DCHECK(page()); 280 DCHECK(page());
275 DCHECK(m_layerTreeView); 281 DCHECK(m_layerTreeView);
276 282
277 float deviceScaleFactor = page()->deviceScaleFactorDeprecated(); 283 float deviceScaleFactor = page()->deviceScaleFactorDeprecated();
278 m_layerTreeView->setDeviceScaleFactor(deviceScaleFactor); 284 m_layerTreeView->setDeviceScaleFactor(deviceScaleFactor);
279 } 285 }
280 286
281 void WebFrameWidgetImpl::setIsTransparent(bool isTransparent) { 287 void WebFrameWidgetImpl::setBackgroundColorOverride(WebColor color) {
282 m_isTransparent = isTransparent; 288 m_backgroundColorOverrideEnabled = true;
283 289 m_backgroundColorOverride = color;
284 if (m_layerTreeView) 290 updateLayerTreeBackgroundColor();
285 m_layerTreeView->setHasTransparentBackground(isTransparent);
286 } 291 }
287 292
288 bool WebFrameWidgetImpl::isTransparent() const { 293 void WebFrameWidgetImpl::clearBackgroundColorOverride() {
289 return m_isTransparent; 294 m_backgroundColorOverrideEnabled = false;
295 updateLayerTreeBackgroundColor();
296 }
297
298 void WebFrameWidgetImpl::setBaseBackgroundColorOverride(WebColor color) {
299 m_baseBackgroundColorOverrideEnabled = true;
300 m_baseBackgroundColorOverride = color;
301 updateBaseBackgroundColor();
302 }
303
304 void WebFrameWidgetImpl::clearBaseBackgroundColorOverride() {
305 m_baseBackgroundColorOverrideEnabled = false;
306 updateBaseBackgroundColor();
290 } 307 }
291 308
292 void WebFrameWidgetImpl::layoutAndPaintAsync( 309 void WebFrameWidgetImpl::layoutAndPaintAsync(
293 WebLayoutAndPaintAsyncCallback* callback) { 310 WebLayoutAndPaintAsyncCallback* callback) {
294 m_layerTreeView->layoutAndPaintAsync(callback); 311 m_layerTreeView->layoutAndPaintAsync(callback);
295 } 312 }
296 313
297 void WebFrameWidgetImpl::compositeAndReadbackAsync( 314 void WebFrameWidgetImpl::compositeAndReadbackAsync(
298 WebCompositeAndReadbackAsyncCallback* callback) { 315 WebCompositeAndReadbackAsyncCallback* callback) {
299 m_layerTreeView->compositeAndReadbackAsync(callback); 316 m_layerTreeView->compositeAndReadbackAsync(callback);
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 void WebFrameWidgetImpl::setCursorVisibilityState(bool isVisible) { 411 void WebFrameWidgetImpl::setCursorVisibilityState(bool isVisible) {
395 page()->setIsCursorVisible(isVisible); 412 page()->setIsCursorVisible(isVisible);
396 } 413 }
397 414
398 bool WebFrameWidgetImpl::hasTouchEventHandlersAt(const WebPoint& point) { 415 bool WebFrameWidgetImpl::hasTouchEventHandlersAt(const WebPoint& point) {
399 // FIXME: Implement this. Note that the point must be divided by 416 // FIXME: Implement this. Note that the point must be divided by
400 // pageScaleFactor. 417 // pageScaleFactor.
401 return true; 418 return true;
402 } 419 }
403 420
421 Color WebFrameWidgetImpl::baseBackgroundColor() const {
422 return m_baseBackgroundColorOverrideEnabled ? m_baseBackgroundColorOverride
423 : m_baseBackgroundColor;
424 }
425
404 void WebFrameWidgetImpl::setBaseBackgroundColor(WebColor color) { 426 void WebFrameWidgetImpl::setBaseBackgroundColor(WebColor color) {
405 if (m_baseBackgroundColor == color) 427 if (m_baseBackgroundColor == color)
406 return; 428 return;
407 429
408 m_baseBackgroundColor = color; 430 m_baseBackgroundColor = color;
431 updateBaseBackgroundColor();
432 }
409 433
410 m_localRoot->frameView()->setBaseBackgroundColor(color); 434 void WebFrameWidgetImpl::updateBaseBackgroundColor() {
435 m_localRoot->frameView()->setBaseBackgroundColor(baseBackgroundColor());
411 } 436 }
412 437
413 WebInputMethodControllerImpl* 438 WebInputMethodControllerImpl*
414 WebFrameWidgetImpl::getActiveWebInputMethodController() const { 439 WebFrameWidgetImpl::getActiveWebInputMethodController() const {
415 return WebInputMethodControllerImpl::fromFrame(focusedLocalFrameInWidget()); 440 return WebInputMethodControllerImpl::fromFrame(focusedLocalFrameInWidget());
416 } 441 }
417 442
418 void WebFrameWidgetImpl::scheduleAnimation() { 443 void WebFrameWidgetImpl::scheduleAnimation() {
419 if (m_layerTreeView) { 444 if (m_layerTreeView) {
420 m_layerTreeView->setNeedsBeginFrame(); 445 m_layerTreeView->setNeedsBeginFrame();
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 DCHECK(editable); 549 DCHECK(editable);
525 550
526 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets 551 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets
527 // needs to be audited. See http://crbug.com/590369 for more details. 552 // needs to be audited. See http://crbug.com/590369 for more details.
528 editable->document().updateStyleAndLayoutIgnorePendingStylesheets(); 553 editable->document().updateStyleAndLayoutIgnorePendingStylesheets();
529 554
530 return PlainTextRange::create(*editable, range); 555 return PlainTextRange::create(*editable, range);
531 } 556 }
532 557
533 WebColor WebFrameWidgetImpl::backgroundColor() const { 558 WebColor WebFrameWidgetImpl::backgroundColor() const {
534 if (isTransparent()) 559 if (m_backgroundColorOverrideEnabled)
535 return Color::transparent; 560 return m_backgroundColorOverride;
536 if (!m_localRoot->frameView()) 561 if (!m_localRoot->frameView())
537 return m_baseBackgroundColor; 562 return m_baseBackgroundColor;
538 FrameView* view = m_localRoot->frameView(); 563 FrameView* view = m_localRoot->frameView();
539 return view->documentBackgroundColor().rgb(); 564 return view->documentBackgroundColor().rgb();
540 } 565 }
541 566
542 // TODO(ekaramad):This method is almost duplicated in WebViewImpl as well. This 567 // TODO(ekaramad):This method is almost duplicated in WebViewImpl as well. This
543 // code needs to be refactored (http://crbug.com/629721). 568 // code needs to be refactored (http://crbug.com/629721).
544 bool WebFrameWidgetImpl::selectionBounds(WebRect& anchor, 569 bool WebFrameWidgetImpl::selectionBounds(WebRect& anchor,
545 WebRect& focus) const { 570 WebRect& focus) const {
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after
1028 return; 1053 return;
1029 1054
1030 if (active) { 1055 if (active) {
1031 TRACE_EVENT0("blink", 1056 TRACE_EVENT0("blink",
1032 "WebViewImpl::setIsAcceleratedCompositingActive(true)"); 1057 "WebViewImpl::setIsAcceleratedCompositingActive(true)");
1033 m_layerTreeView->setRootLayer(*m_rootLayer); 1058 m_layerTreeView->setRootLayer(*m_rootLayer);
1034 1059
1035 m_layerTreeView->setVisible(page()->isPageVisible()); 1060 m_layerTreeView->setVisible(page()->isPageVisible());
1036 updateLayerTreeDeviceScaleFactor(); 1061 updateLayerTreeDeviceScaleFactor();
1037 updateLayerTreeBackgroundColor(); 1062 updateLayerTreeBackgroundColor();
1038 m_layerTreeView->setHasTransparentBackground(isTransparent());
1039 updateLayerTreeViewport(); 1063 updateLayerTreeViewport();
1040 m_isAcceleratedCompositingActive = true; 1064 m_isAcceleratedCompositingActive = true;
1041 } 1065 }
1042 } 1066 }
1043 1067
1044 PaintLayerCompositor* WebFrameWidgetImpl::compositor() const { 1068 PaintLayerCompositor* WebFrameWidgetImpl::compositor() const {
1045 LocalFrame* frame = m_localRoot->frame(); 1069 LocalFrame* frame = m_localRoot->frame();
1046 if (!frame || !frame->document() || 1070 if (!frame || !frame->document() ||
1047 frame->document()->layoutViewItem().isNull()) 1071 frame->document()->layoutViewItem().isNull())
1048 return nullptr; 1072 return nullptr;
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
1138 return nullptr; 1162 return nullptr;
1139 } 1163 }
1140 1164
1141 LocalFrame* WebFrameWidgetImpl::focusedLocalFrameAvailableForIme() const { 1165 LocalFrame* WebFrameWidgetImpl::focusedLocalFrameAvailableForIme() const {
1142 if (!m_imeAcceptEvents) 1166 if (!m_imeAcceptEvents)
1143 return nullptr; 1167 return nullptr;
1144 return focusedLocalFrameInWidget(); 1168 return focusedLocalFrameInWidget();
1145 } 1169 }
1146 1170
1147 } // namespace blink 1171 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698