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

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: add unit test for remote frame transparency Created 3 years, 8 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/FrameView.h" 41 #include "core/frame/FrameView.h"
40 #include "core/frame/RemoteFrame.h" 42 #include "core/frame/RemoteFrame.h"
41 #include "core/frame/Settings.h" 43 #include "core/frame/Settings.h"
42 #include "core/frame/VisualViewport.h" 44 #include "core/frame/VisualViewport.h"
43 #include "core/html/HTMLTextAreaElement.h" 45 #include "core/html/HTMLTextAreaElement.h"
44 #include "core/input/EventHandler.h" 46 #include "core/input/EventHandler.h"
45 #include "core/layout/LayoutView.h" 47 #include "core/layout/LayoutView.h"
46 #include "core/layout/api/LayoutViewItem.h" 48 #include "core/layout/api/LayoutViewItem.h"
47 #include "core/layout/compositing/PaintLayerCompositor.h" 49 #include "core/layout/compositing/PaintLayerCompositor.h"
48 #include "core/page/ContextMenuController.h" 50 #include "core/page/ContextMenuController.h"
49 #include "core/page/FocusController.h" 51 #include "core/page/FocusController.h"
50 #include "core/page/Page.h" 52 #include "core/page/Page.h"
51 #include "core/page/PointerLockController.h" 53 #include "core/page/PointerLockController.h"
52 #include "platform/KeyboardCodes.h" 54 #include "platform/KeyboardCodes.h"
53 #include "platform/WebFrameScheduler.h" 55 #include "platform/WebFrameScheduler.h"
54 #include "platform/animation/CompositorAnimationHost.h" 56 #include "platform/animation/CompositorAnimationHost.h"
57 #include "platform/graphics/Color.h"
55 #include "platform/graphics/CompositorMutatorClient.h" 58 #include "platform/graphics/CompositorMutatorClient.h"
56 #include "public/web/WebAutofillClient.h" 59 #include "public/web/WebAutofillClient.h"
57 #include "public/web/WebPlugin.h" 60 #include "public/web/WebPlugin.h"
58 #include "public/web/WebRange.h" 61 #include "public/web/WebRange.h"
59 #include "public/web/WebWidgetClient.h" 62 #include "public/web/WebWidgetClient.h"
60 #include "web/AnimationWorkletProxyClientImpl.h" 63 #include "web/AnimationWorkletProxyClientImpl.h"
61 #include "web/CompositionUnderlineVectorBuilder.h" 64 #include "web/CompositionUnderlineVectorBuilder.h"
62 #include "web/CompositorMutatorImpl.h" 65 #include "web/CompositorMutatorImpl.h"
63 #include "web/CompositorWorkerProxyClientImpl.h" 66 #include "web/CompositorWorkerProxyClientImpl.h"
64 #include "web/ContextMenuAllowedScope.h" 67 #include "web/ContextMenuAllowedScope.h"
65 #include "web/InspectorOverlay.h" 68 #include "web/InspectorOverlay.h"
66 #include "web/PageOverlay.h" 69 #include "web/PageOverlay.h"
67 #include "web/WebDevToolsAgentImpl.h" 70 #include "web/WebDevToolsAgentImpl.h"
68 #include "web/WebInputEventConversion.h" 71 #include "web/WebInputEventConversion.h"
69 #include "web/WebInputMethodControllerImpl.h" 72 #include "web/WebInputMethodControllerImpl.h"
70 #include "web/WebLocalFrameImpl.h" 73 #include "web/WebLocalFrameImpl.h"
71 #include "web/WebPluginContainerImpl.h" 74 #include "web/WebPluginContainerImpl.h"
72 #include "web/WebRemoteFrameImpl.h" 75 #include "web/WebRemoteFrameImpl.h"
73 #include "web/WebViewFrameWidget.h" 76 #include "web/WebViewFrameWidget.h"
74 #include "wtf/AutoReset.h" 77 #include "wtf/AutoReset.h"
75 #include "wtf/PtrUtil.h" 78 #include "wtf/PtrUtil.h"
76 #include <memory>
77 79
78 namespace blink { 80 namespace blink {
79 81
80 // WebFrameWidget ------------------------------------------------------------ 82 // WebFrameWidget ------------------------------------------------------------
81 83
82 WebFrameWidget* WebFrameWidget::create(WebWidgetClient* client, 84 WebFrameWidget* WebFrameWidget::create(WebWidgetClient* client,
83 WebLocalFrame* localRoot) { 85 WebLocalFrame* localRoot) {
84 DCHECK(client) << "A valid WebWidgetClient must be supplied."; 86 DCHECK(client) << "A valid WebWidgetClient must be supplied.";
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);
(...skipping 19 matching lines...) Expand all
106 WebLocalFrame* localRoot) 108 WebLocalFrame* localRoot)
107 : m_client(client), 109 : m_client(client),
108 m_localRoot(toWebLocalFrameImpl(localRoot)), 110 m_localRoot(toWebLocalFrameImpl(localRoot)),
109 m_mutator(nullptr), 111 m_mutator(nullptr),
110 m_layerTreeView(nullptr), 112 m_layerTreeView(nullptr),
111 m_rootLayer(nullptr), 113 m_rootLayer(nullptr),
112 m_rootGraphicsLayer(nullptr), 114 m_rootGraphicsLayer(nullptr),
113 m_isAcceleratedCompositingActive(false), 115 m_isAcceleratedCompositingActive(false),
114 m_layerTreeViewClosed(false), 116 m_layerTreeViewClosed(false),
115 m_suppressNextKeypressEvent(false), 117 m_suppressNextKeypressEvent(false),
116 m_isTransparent(false), 118 m_backgroundColorOverrideEnabled(false),
119 m_backgroundColorOverride(Color::transparent),
120 m_baseBackgroundColorOverrideEnabled(false),
121 m_baseBackgroundColorOverride(Color::transparent),
117 m_imeAcceptEvents(true), 122 m_imeAcceptEvents(true),
118 m_selfKeepAlive(this) { 123 m_selfKeepAlive(this) {
119 DCHECK(m_localRoot->frame()->isLocalRoot()); 124 DCHECK(m_localRoot->frame()->isLocalRoot());
120 initializeLayerTreeView(); 125 initializeLayerTreeView();
121 m_localRoot->setFrameWidget(this); 126 m_localRoot->setFrameWidget(this);
122 127
123 if (localRoot->parent()) 128 if (localRoot->parent())
124 setIsTransparent(true); 129 setBackgroundColorOverride(Color::transparent);
125 } 130 }
126 131
127 WebFrameWidgetImpl::~WebFrameWidgetImpl() {} 132 WebFrameWidgetImpl::~WebFrameWidgetImpl() {}
128 133
129 DEFINE_TRACE(WebFrameWidgetImpl) { 134 DEFINE_TRACE(WebFrameWidgetImpl) {
130 visitor->trace(m_localRoot); 135 visitor->trace(m_localRoot);
131 visitor->trace(m_mouseCaptureNode); 136 visitor->trace(m_mouseCaptureNode);
132 } 137 }
133 138
134 // WebWidget ------------------------------------------------------------------ 139 // WebWidget ------------------------------------------------------------------
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 // Pass the limits even though this is for subframes, as the limits will be 267 // Pass the limits even though this is for subframes, as the limits will be
263 // needed in setting the raster scale. 268 // needed in setting the raster scale.
264 m_layerTreeView->setPageScaleFactorAndLimits( 269 m_layerTreeView->setPageScaleFactorAndLimits(
265 1, view()->minimumPageScaleFactor(), view()->maximumPageScaleFactor()); 270 1, view()->minimumPageScaleFactor(), view()->maximumPageScaleFactor());
266 } 271 }
267 272
268 void WebFrameWidgetImpl::updateLayerTreeBackgroundColor() { 273 void WebFrameWidgetImpl::updateLayerTreeBackgroundColor() {
269 if (!m_layerTreeView) 274 if (!m_layerTreeView)
270 return; 275 return;
271 276
272 m_layerTreeView->setBackgroundColor(backgroundColor()); 277 WebColor color = backgroundColor();
278 m_layerTreeView->setBackgroundColor(color);
273 } 279 }
274 280
275 void WebFrameWidgetImpl::updateLayerTreeDeviceScaleFactor() { 281 void WebFrameWidgetImpl::updateLayerTreeDeviceScaleFactor() {
276 DCHECK(page()); 282 DCHECK(page());
277 DCHECK(m_layerTreeView); 283 DCHECK(m_layerTreeView);
278 284
279 float deviceScaleFactor = page()->deviceScaleFactorDeprecated(); 285 float deviceScaleFactor = page()->deviceScaleFactorDeprecated();
280 m_layerTreeView->setDeviceScaleFactor(deviceScaleFactor); 286 m_layerTreeView->setDeviceScaleFactor(deviceScaleFactor);
281 } 287 }
282 288
283 void WebFrameWidgetImpl::setIsTransparent(bool isTransparent) { 289 void WebFrameWidgetImpl::setBackgroundColorOverride(WebColor color) {
284 m_isTransparent = isTransparent; 290 m_backgroundColorOverrideEnabled = true;
285 291 m_backgroundColorOverride = color;
286 if (m_layerTreeView) 292 updateLayerTreeBackgroundColor();
287 m_layerTreeView->setHasTransparentBackground(isTransparent);
288 } 293 }
289 294
290 bool WebFrameWidgetImpl::isTransparent() const { 295 void WebFrameWidgetImpl::clearBackgroundColorOverride() {
291 return m_isTransparent; 296 m_backgroundColorOverrideEnabled = false;
297 updateLayerTreeBackgroundColor();
298 }
299
300 void WebFrameWidgetImpl::setBaseBackgroundColorOverride(WebColor color) {
301 m_baseBackgroundColorOverrideEnabled = true;
302 m_baseBackgroundColorOverride = color;
303 updateBaseBackgroundColor();
304 }
305
306 void WebFrameWidgetImpl::clearBaseBackgroundColorOverride() {
307 m_baseBackgroundColorOverrideEnabled = false;
308 updateBaseBackgroundColor();
292 } 309 }
293 310
294 void WebFrameWidgetImpl::layoutAndPaintAsync( 311 void WebFrameWidgetImpl::layoutAndPaintAsync(
295 WebLayoutAndPaintAsyncCallback* callback) { 312 WebLayoutAndPaintAsyncCallback* callback) {
296 m_layerTreeView->layoutAndPaintAsync(callback); 313 m_layerTreeView->layoutAndPaintAsync(callback);
297 } 314 }
298 315
299 void WebFrameWidgetImpl::compositeAndReadbackAsync( 316 void WebFrameWidgetImpl::compositeAndReadbackAsync(
300 WebCompositeAndReadbackAsyncCallback* callback) { 317 WebCompositeAndReadbackAsyncCallback* callback) {
301 m_layerTreeView->compositeAndReadbackAsync(callback); 318 m_layerTreeView->compositeAndReadbackAsync(callback);
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 void WebFrameWidgetImpl::setCursorVisibilityState(bool isVisible) { 413 void WebFrameWidgetImpl::setCursorVisibilityState(bool isVisible) {
397 page()->setIsCursorVisible(isVisible); 414 page()->setIsCursorVisible(isVisible);
398 } 415 }
399 416
400 bool WebFrameWidgetImpl::hasTouchEventHandlersAt(const WebPoint& point) { 417 bool WebFrameWidgetImpl::hasTouchEventHandlersAt(const WebPoint& point) {
401 // FIXME: Implement this. Note that the point must be divided by 418 // FIXME: Implement this. Note that the point must be divided by
402 // pageScaleFactor. 419 // pageScaleFactor.
403 return true; 420 return true;
404 } 421 }
405 422
423 Color WebFrameWidgetImpl::baseBackgroundColor() const {
424 return m_baseBackgroundColorOverrideEnabled ? m_baseBackgroundColorOverride
425 : m_baseBackgroundColor;
426 }
427
406 void WebFrameWidgetImpl::setBaseBackgroundColor(WebColor color) { 428 void WebFrameWidgetImpl::setBaseBackgroundColor(WebColor color) {
407 if (m_baseBackgroundColor == color) 429 if (m_baseBackgroundColor == color)
408 return; 430 return;
409 431
410 m_baseBackgroundColor = color; 432 m_baseBackgroundColor = color;
433 updateBaseBackgroundColor();
434 }
411 435
412 m_localRoot->frameView()->setBaseBackgroundColor(color); 436 void WebFrameWidgetImpl::updateBaseBackgroundColor() {
437 m_localRoot->frameView()->setBaseBackgroundColor(baseBackgroundColor());
413 } 438 }
414 439
415 WebInputMethodControllerImpl* 440 WebInputMethodControllerImpl*
416 WebFrameWidgetImpl::getActiveWebInputMethodController() const { 441 WebFrameWidgetImpl::getActiveWebInputMethodController() const {
417 return WebInputMethodControllerImpl::fromFrame(focusedLocalFrameInWidget()); 442 return WebInputMethodControllerImpl::fromFrame(focusedLocalFrameInWidget());
418 } 443 }
419 444
420 void WebFrameWidgetImpl::scheduleAnimation() { 445 void WebFrameWidgetImpl::scheduleAnimation() {
421 if (m_layerTreeView) { 446 if (m_layerTreeView) {
422 m_layerTreeView->setNeedsBeginFrame(); 447 m_layerTreeView->setNeedsBeginFrame();
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 DCHECK(editable); 551 DCHECK(editable);
527 552
528 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets 553 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets
529 // needs to be audited. See http://crbug.com/590369 for more details. 554 // needs to be audited. See http://crbug.com/590369 for more details.
530 editable->document().updateStyleAndLayoutIgnorePendingStylesheets(); 555 editable->document().updateStyleAndLayoutIgnorePendingStylesheets();
531 556
532 return PlainTextRange::create(*editable, range); 557 return PlainTextRange::create(*editable, range);
533 } 558 }
534 559
535 WebColor WebFrameWidgetImpl::backgroundColor() const { 560 WebColor WebFrameWidgetImpl::backgroundColor() const {
536 if (isTransparent()) 561 if (m_backgroundColorOverrideEnabled)
537 return Color::transparent; 562 return m_backgroundColorOverride;
538 if (!m_localRoot->frameView()) 563 if (!m_localRoot->frameView())
539 return m_baseBackgroundColor; 564 return m_baseBackgroundColor;
540 FrameView* view = m_localRoot->frameView(); 565 FrameView* view = m_localRoot->frameView();
541 return view->documentBackgroundColor().rgb(); 566 return view->documentBackgroundColor().rgb();
542 } 567 }
543 568
544 // TODO(ekaramad):This method is almost duplicated in WebViewImpl as well. This 569 // TODO(ekaramad):This method is almost duplicated in WebViewImpl as well. This
545 // code needs to be refactored (http://crbug.com/629721). 570 // code needs to be refactored (http://crbug.com/629721).
546 bool WebFrameWidgetImpl::selectionBounds(WebRect& anchor, 571 bool WebFrameWidgetImpl::selectionBounds(WebRect& anchor,
547 WebRect& focus) const { 572 WebRect& focus) const {
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after
1023 return; 1048 return;
1024 1049
1025 if (active) { 1050 if (active) {
1026 TRACE_EVENT0("blink", 1051 TRACE_EVENT0("blink",
1027 "WebViewImpl::setIsAcceleratedCompositingActive(true)"); 1052 "WebViewImpl::setIsAcceleratedCompositingActive(true)");
1028 m_layerTreeView->setRootLayer(*m_rootLayer); 1053 m_layerTreeView->setRootLayer(*m_rootLayer);
1029 1054
1030 m_layerTreeView->setVisible(page()->isPageVisible()); 1055 m_layerTreeView->setVisible(page()->isPageVisible());
1031 updateLayerTreeDeviceScaleFactor(); 1056 updateLayerTreeDeviceScaleFactor();
1032 updateLayerTreeBackgroundColor(); 1057 updateLayerTreeBackgroundColor();
1033 m_layerTreeView->setHasTransparentBackground(isTransparent());
1034 updateLayerTreeViewport(); 1058 updateLayerTreeViewport();
1035 m_isAcceleratedCompositingActive = true; 1059 m_isAcceleratedCompositingActive = true;
1036 } 1060 }
1037 } 1061 }
1038 1062
1039 PaintLayerCompositor* WebFrameWidgetImpl::compositor() const { 1063 PaintLayerCompositor* WebFrameWidgetImpl::compositor() const {
1040 LocalFrame* frame = m_localRoot->frame(); 1064 LocalFrame* frame = m_localRoot->frame();
1041 if (!frame || !frame->document() || 1065 if (!frame || !frame->document() ||
1042 frame->document()->layoutViewItem().isNull()) 1066 frame->document()->layoutViewItem().isNull())
1043 return nullptr; 1067 return nullptr;
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
1133 return nullptr; 1157 return nullptr;
1134 } 1158 }
1135 1159
1136 LocalFrame* WebFrameWidgetImpl::focusedLocalFrameAvailableForIme() const { 1160 LocalFrame* WebFrameWidgetImpl::focusedLocalFrameAvailableForIme() const {
1137 if (!m_imeAcceptEvents) 1161 if (!m_imeAcceptEvents)
1138 return nullptr; 1162 return nullptr;
1139 return focusedLocalFrameInWidget(); 1163 return focusedLocalFrameInWidget();
1140 } 1164 }
1141 1165
1142 } // namespace blink 1166 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698