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

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

Powered by Google App Engine
This is Rietveld 408576698