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

Side by Side Diff: Source/core/frame/PinchViewport.cpp

Issue 640063002: Hide scrollbars when their dimensions are not scrollable. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 2 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
« no previous file with comments | « Source/core/frame/PinchViewport.h ('k') | Source/web/WebViewImpl.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 using blink::WebScrollbarLayer; 60 using blink::WebScrollbarLayer;
61 using blink::FrameHost; 61 using blink::FrameHost;
62 using blink::GraphicsLayer; 62 using blink::GraphicsLayer;
63 using blink::GraphicsLayerFactory; 63 using blink::GraphicsLayerFactory;
64 64
65 namespace blink { 65 namespace blink {
66 66
67 PinchViewport::PinchViewport(FrameHost& owner) 67 PinchViewport::PinchViewport(FrameHost& owner)
68 : m_frameHost(owner) 68 : m_frameHost(owner)
69 , m_scale(1) 69 , m_scale(1)
70 , m_hasHorizontalScrollbar(false)
71 , m_hasVerticalScrollbar(false)
70 { 72 {
71 reset(); 73 reset();
72 } 74 }
73 75
74 PinchViewport::~PinchViewport() { } 76 PinchViewport::~PinchViewport() { }
75 77
76 void PinchViewport::setSize(const IntSize& size) 78 void PinchViewport::setSize(const IntSize& size)
77 { 79 {
78 if (m_size == size) 80 if (m_size == size)
79 return; 81 return;
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 } 154 }
153 155
154 void PinchViewport::move(const FloatPoint& delta) 156 void PinchViewport::move(const FloatPoint& delta)
155 { 157 {
156 setLocation(m_offset + delta); 158 setLocation(m_offset + delta);
157 } 159 }
158 160
159 void PinchViewport::setScale(float scale) 161 void PinchViewport::setScale(float scale)
160 { 162 {
161 setScaleAndLocation(scale, m_offset); 163 setScaleAndLocation(scale, m_offset);
164 adjustScrollbarExistence();
bokan 2014/10/09 15:22:14 Should we also call this in setSize?
162 } 165 }
163 166
164 void PinchViewport::setScaleAndLocation(float scale, const FloatPoint& location) 167 void PinchViewport::setScaleAndLocation(float scale, const FloatPoint& location)
165 { 168 {
166 bool valuesChanged = false; 169 bool valuesChanged = false;
167 170
168 if (scale != m_scale) { 171 if (scale != m_scale) {
169 m_scale = scale; 172 m_scale = scale;
170 valuesChanged = true; 173 valuesChanged = true;
171 } 174 }
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 int yPosition = isHorizontal ? m_innerViewportContainerLayer->size().height( ) - scrollbarThickness : 0; 310 int yPosition = isHorizontal ? m_innerViewportContainerLayer->size().height( ) - scrollbarThickness : 0;
308 int width = isHorizontal ? m_innerViewportContainerLayer->size().width() - s crollbarThickness : scrollbarThickness; 311 int width = isHorizontal ? m_innerViewportContainerLayer->size().width() - s crollbarThickness : scrollbarThickness;
309 int height = isHorizontal ? scrollbarThickness : m_innerViewportContainerLay er->size().height() - scrollbarThickness; 312 int height = isHorizontal ? scrollbarThickness : m_innerViewportContainerLay er->size().height() - scrollbarThickness;
310 313
311 // Use the GraphicsLayer to position the scrollbars. 314 // Use the GraphicsLayer to position the scrollbars.
312 scrollbarGraphicsLayer->setPosition(IntPoint(xPosition, yPosition)); 315 scrollbarGraphicsLayer->setPosition(IntPoint(xPosition, yPosition));
313 scrollbarGraphicsLayer->setSize(IntSize(width, height)); 316 scrollbarGraphicsLayer->setSize(IntSize(width, height));
314 scrollbarGraphicsLayer->setContentsRect(IntRect(0, 0, width, height)); 317 scrollbarGraphicsLayer->setContentsRect(IntRect(0, 0, width, height));
315 } 318 }
316 319
320 void PinchViewport::adjustScrollbarExistence()
321 {
322 IntSize visibleSize = enclosingIntRect(visibleRect()).size();
323
324 ASSERT(mainFrame());
325 ASSERT(mainFrame()->contentRenderer());
326 IntSize documentSize = mainFrame()->contentRenderer()->documentRect().size() ;
327
328 bool oldHasHorizontal = m_hasHorizontalScrollbar;
329 bool oldHasVertical = m_hasVerticalScrollbar;
330 m_hasHorizontalScrollbar = visibleSize.width() < documentSize.width();
331 m_hasVerticalScrollbar = visibleSize.height() < documentSize.height();
bokan 2014/10/09 15:22:14 Rather than comparing the sizes yourself here, jus
332
333 if (oldHasHorizontal != m_hasHorizontalScrollbar || oldHasVertical != m_hasV erticalScrollbar) {
334 GraphicsLayerVector children;
335 children.append(m_pageScaleLayer.get());
336
337 if (m_hasHorizontalScrollbar)
338 children.append(m_overlayScrollbarHorizontal.get());
339 if (m_hasVerticalScrollbar)
340 children.append(m_overlayScrollbarVertical.get());
341
342 m_innerViewportContainerLayer->setChildren(children);
bokan 2014/10/09 15:22:14 Hmm...I'm not sure what the implications of freque
343 }
344 }
345
317 void PinchViewport::registerLayersWithTreeView(WebLayerTreeView* layerTreeView) const 346 void PinchViewport::registerLayersWithTreeView(WebLayerTreeView* layerTreeView) const
318 { 347 {
319 TRACE_EVENT0("blink", "PinchViewport::registerLayersWithTreeView"); 348 TRACE_EVENT0("blink", "PinchViewport::registerLayersWithTreeView");
320 ASSERT(layerTreeView); 349 ASSERT(layerTreeView);
321 ASSERT(m_frameHost.page().mainFrame()); 350 ASSERT(m_frameHost.page().mainFrame());
322 ASSERT(m_frameHost.page().mainFrame()->isLocalFrame()); 351 ASSERT(m_frameHost.page().mainFrame()->isLocalFrame());
323 ASSERT(m_frameHost.page().deprecatedLocalMainFrame()->contentRenderer()); 352 ASSERT(m_frameHost.page().deprecatedLocalMainFrame()->contentRenderer());
324 353
325 RenderLayerCompositor* compositor = m_frameHost.page().deprecatedLocalMainFr ame()->contentRenderer()->compositor(); 354 RenderLayerCompositor* compositor = m_frameHost.page().deprecatedLocalMainFr ame()->contentRenderer()->compositor();
326 // Get the outer viewport scroll layer. 355 // Get the outer viewport scroll layer.
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 return m_innerViewportContainerLayer.get(); 449 return m_innerViewportContainerLayer.get();
421 } 450 }
422 451
423 GraphicsLayer* PinchViewport::layerForScrolling() const 452 GraphicsLayer* PinchViewport::layerForScrolling() const
424 { 453 {
425 return m_innerViewportScrollLayer.get(); 454 return m_innerViewportScrollLayer.get();
426 } 455 }
427 456
428 GraphicsLayer* PinchViewport::layerForHorizontalScrollbar() const 457 GraphicsLayer* PinchViewport::layerForHorizontalScrollbar() const
429 { 458 {
430 return m_overlayScrollbarHorizontal.get(); 459 return m_hasHorizontalScrollbar ? m_overlayScrollbarHorizontal.get() : nullp tr;
431 } 460 }
432 461
433 GraphicsLayer* PinchViewport::layerForVerticalScrollbar() const 462 GraphicsLayer* PinchViewport::layerForVerticalScrollbar() const
434 { 463 {
435 return m_overlayScrollbarVertical.get(); 464 return m_hasVerticalScrollbar ? m_overlayScrollbarVertical.get() : nullptr;
436 } 465 }
437 466
438 void PinchViewport::notifyAnimationStarted(const GraphicsLayer*, double monotoni cTime) 467 void PinchViewport::notifyAnimationStarted(const GraphicsLayer*, double monotoni cTime)
439 { 468 {
440 } 469 }
441 470
442 void PinchViewport::paintContents(const GraphicsLayer*, GraphicsContext&, Graphi csLayerPaintingPhase, const IntRect& inClip) 471 void PinchViewport::paintContents(const GraphicsLayer*, GraphicsContext&, Graphi csLayerPaintingPhase, const IntRect& inClip)
443 { 472 {
444 } 473 }
445 474
(...skipping 29 matching lines...) Expand all
475 } else if (graphicsLayer == m_overlayScrollbarVertical.get()) { 504 } else if (graphicsLayer == m_overlayScrollbarVertical.get()) {
476 name = "Overlay Scrollbar Vertical Layer"; 505 name = "Overlay Scrollbar Vertical Layer";
477 } else { 506 } else {
478 ASSERT_NOT_REACHED(); 507 ASSERT_NOT_REACHED();
479 } 508 }
480 509
481 return name; 510 return name;
482 } 511 }
483 512
484 } // namespace blink 513 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/frame/PinchViewport.h ('k') | Source/web/WebViewImpl.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698