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

Side by Side Diff: third_party/WebKit/Source/core/page/scrolling/ScrollingCoordinator.cpp

Issue 2728253002: Remove indirection: setup scrollbar scroll layers in the scrollbar constructor (Closed)
Patch Set: Really fix reivewer comment 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) 2011 Apple Inc. All rights reserved. 2 * Copyright (C) 2011 Apple 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 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 ScrollbarMap& scrollbars = orientation == HorizontalScrollbar 332 ScrollbarMap& scrollbars = orientation == HorizontalScrollbar
333 ? m_horizontalScrollbars 333 ? m_horizontalScrollbars
334 : m_verticalScrollbars; 334 : m_verticalScrollbars;
335 if (std::unique_ptr<WebScrollbarLayer> scrollbarLayer = 335 if (std::unique_ptr<WebScrollbarLayer> scrollbarLayer =
336 scrollbars.take(scrollableArea)) 336 scrollbars.take(scrollableArea))
337 GraphicsLayer::unregisterContentsLayer(scrollbarLayer->layer()); 337 GraphicsLayer::unregisterContentsLayer(scrollbarLayer->layer());
338 } 338 }
339 339
340 static std::unique_ptr<WebScrollbarLayer> createScrollbarLayer( 340 static std::unique_ptr<WebScrollbarLayer> createScrollbarLayer(
341 Scrollbar& scrollbar, 341 Scrollbar& scrollbar,
342 float deviceScaleFactor) { 342 float deviceScaleFactor,
343 WebLayer* scrollLayer) {
343 ScrollbarTheme& theme = scrollbar.theme(); 344 ScrollbarTheme& theme = scrollbar.theme();
344 WebScrollbarThemePainter painter(theme, scrollbar, deviceScaleFactor); 345 WebScrollbarThemePainter painter(theme, scrollbar, deviceScaleFactor);
345 std::unique_ptr<WebScrollbarThemeGeometry> geometry( 346 std::unique_ptr<WebScrollbarThemeGeometry> geometry(
346 WebScrollbarThemeGeometryNative::create(theme)); 347 WebScrollbarThemeGeometryNative::create(theme));
347 348
348 std::unique_ptr<WebScrollbarLayer> scrollbarLayer; 349 std::unique_ptr<WebScrollbarLayer> scrollbarLayer;
349 if (theme.usesOverlayScrollbars() && theme.usesNinePatchThumbResource()) { 350 if (theme.usesOverlayScrollbars() && theme.usesNinePatchThumbResource()) {
350 scrollbarLayer = 351 scrollbarLayer =
351 Platform::current()->compositorSupport()->createOverlayScrollbarLayer( 352 Platform::current()->compositorSupport()->createOverlayScrollbarLayer(
352 WebScrollbarImpl::create(&scrollbar), painter, std::move(geometry)); 353 WebScrollbarImpl::create(&scrollbar), painter, std::move(geometry),
354 scrollLayer);
353 } else { 355 } else {
354 scrollbarLayer = 356 scrollbarLayer =
355 Platform::current()->compositorSupport()->createScrollbarLayer( 357 Platform::current()->compositorSupport()->createScrollbarLayer(
356 WebScrollbarImpl::create(&scrollbar), painter, std::move(geometry)); 358 WebScrollbarImpl::create(&scrollbar), painter, std::move(geometry),
359 scrollLayer);
357 } 360 }
358 GraphicsLayer::registerContentsLayer(scrollbarLayer->layer()); 361 GraphicsLayer::registerContentsLayer(scrollbarLayer->layer());
359 return scrollbarLayer; 362 return scrollbarLayer;
360 } 363 }
361 364
362 std::unique_ptr<WebScrollbarLayer> 365 std::unique_ptr<WebScrollbarLayer>
363 ScrollingCoordinator::createSolidColorScrollbarLayer( 366 ScrollingCoordinator::createSolidColorScrollbarLayer(
364 ScrollbarOrientation orientation, 367 ScrollbarOrientation orientation,
365 int thumbThickness, 368 int thumbThickness,
366 int trackStart, 369 int trackStart,
367 bool isLeftSideVerticalScrollbar) { 370 bool isLeftSideVerticalScrollbar,
371 WebLayer* scrollLayer) {
368 WebScrollbar::Orientation webOrientation = 372 WebScrollbar::Orientation webOrientation =
369 (orientation == HorizontalScrollbar) ? WebScrollbar::Horizontal 373 (orientation == HorizontalScrollbar) ? WebScrollbar::Horizontal
370 : WebScrollbar::Vertical; 374 : WebScrollbar::Vertical;
371 std::unique_ptr<WebScrollbarLayer> scrollbarLayer = 375 std::unique_ptr<WebScrollbarLayer> scrollbarLayer =
372 Platform::current()->compositorSupport()->createSolidColorScrollbarLayer( 376 Platform::current()->compositorSupport()->createSolidColorScrollbarLayer(
373 webOrientation, thumbThickness, trackStart, 377 webOrientation, thumbThickness, trackStart,
374 isLeftSideVerticalScrollbar); 378 isLeftSideVerticalScrollbar, scrollLayer);
375 GraphicsLayer::registerContentsLayer(scrollbarLayer->layer()); 379 GraphicsLayer::registerContentsLayer(scrollbarLayer->layer());
376 return scrollbarLayer; 380 return scrollbarLayer;
377 } 381 }
378 382
379 static void detachScrollbarLayer(GraphicsLayer* scrollbarGraphicsLayer) { 383 static void detachScrollbarLayer(GraphicsLayer* scrollbarGraphicsLayer) {
380 DCHECK(scrollbarGraphicsLayer); 384 DCHECK(scrollbarGraphicsLayer);
381 385
382 scrollbarGraphicsLayer->setContentsToPlatformLayer(nullptr); 386 scrollbarGraphicsLayer->setContentsToPlatformLayer(nullptr);
383 scrollbarGraphicsLayer->setDrawsContent(true); 387 scrollbarGraphicsLayer->setDrawsContent(true);
384 } 388 }
385 389
386 static void setupScrollbarLayer(GraphicsLayer* scrollbarGraphicsLayer, 390 static void setupScrollbarLayer(GraphicsLayer* scrollbarGraphicsLayer,
387 WebScrollbarLayer* scrollbarLayer, 391 WebScrollbarLayer* scrollbarLayer,
388 WebLayer* scrollLayer) { 392 WebLayer* scrollLayer) {
389 DCHECK(scrollbarGraphicsLayer); 393 DCHECK(scrollbarGraphicsLayer);
390 DCHECK(scrollbarLayer); 394 DCHECK(scrollbarLayer);
391 395
392 if (!scrollLayer) { 396 if (!scrollLayer) {
393 detachScrollbarLayer(scrollbarGraphicsLayer); 397 detachScrollbarLayer(scrollbarGraphicsLayer);
394 return; 398 return;
395 } 399 }
396 scrollbarLayer->setScrollLayer(scrollLayer);
397 scrollbarGraphicsLayer->setContentsToPlatformLayer(scrollbarLayer->layer()); 400 scrollbarGraphicsLayer->setContentsToPlatformLayer(scrollbarLayer->layer());
398 scrollbarGraphicsLayer->setDrawsContent(false); 401 scrollbarGraphicsLayer->setDrawsContent(false);
399 } 402 }
400 403
401 WebScrollbarLayer* ScrollingCoordinator::addWebScrollbarLayer( 404 WebScrollbarLayer* ScrollingCoordinator::addWebScrollbarLayer(
402 ScrollableArea* scrollableArea, 405 ScrollableArea* scrollableArea,
403 ScrollbarOrientation orientation, 406 ScrollbarOrientation orientation,
404 std::unique_ptr<WebScrollbarLayer> scrollbarLayer) { 407 std::unique_ptr<WebScrollbarLayer> scrollbarLayer) {
405 ScrollbarMap& scrollbars = orientation == HorizontalScrollbar 408 ScrollbarMap& scrollbars = orientation == HorizontalScrollbar
406 ? m_horizontalScrollbars 409 ? m_horizontalScrollbars
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 detachScrollbarLayer(scrollbarGraphicsLayer); 441 detachScrollbarLayer(scrollbarGraphicsLayer);
439 scrollbarGraphicsLayer->platformLayer()->addMainThreadScrollingReasons( 442 scrollbarGraphicsLayer->platformLayer()->addMainThreadScrollingReasons(
440 MainThreadScrollingReason::kCustomScrollbarScrolling); 443 MainThreadScrollingReason::kCustomScrollbarScrolling);
441 return; 444 return;
442 } 445 }
443 446
444 // Invalidate custom scrollbar scrolling reason in case a custom 447 // Invalidate custom scrollbar scrolling reason in case a custom
445 // scrollbar becomes a non-custom one. 448 // scrollbar becomes a non-custom one.
446 scrollbarGraphicsLayer->platformLayer()->clearMainThreadScrollingReasons( 449 scrollbarGraphicsLayer->platformLayer()->clearMainThreadScrollingReasons(
447 MainThreadScrollingReason::kCustomScrollbarScrolling); 450 MainThreadScrollingReason::kCustomScrollbarScrolling);
451
452 WebLayer* scrollLayer = toWebLayer(scrollableArea->layerForScrolling());
453 if (!scrollLayer) {
454 detachScrollbarLayer(scrollbarGraphicsLayer);
455 return;
456 }
457
448 WebScrollbarLayer* scrollbarLayer = 458 WebScrollbarLayer* scrollbarLayer =
449 getWebScrollbarLayer(scrollableArea, orientation); 459 getWebScrollbarLayer(scrollableArea, orientation);
450 if (!scrollbarLayer) { 460 if (!scrollbarLayer) {
451 Settings* settings = m_page->mainFrame()->settings(); 461 Settings* settings = m_page->mainFrame()->settings();
452 462
453 std::unique_ptr<WebScrollbarLayer> webScrollbarLayer; 463 std::unique_ptr<WebScrollbarLayer> webScrollbarLayer;
454 if (settings->getUseSolidColorScrollbars()) { 464 if (settings->getUseSolidColorScrollbars()) {
455 DCHECK(RuntimeEnabledFeatures::overlayScrollbarsEnabled()); 465 DCHECK(RuntimeEnabledFeatures::overlayScrollbarsEnabled());
456 webScrollbarLayer = createSolidColorScrollbarLayer( 466 webScrollbarLayer = createSolidColorScrollbarLayer(
457 orientation, scrollbar.theme().thumbThickness(scrollbar), 467 orientation, scrollbar.theme().thumbThickness(scrollbar),
458 scrollbar.theme().trackPosition(scrollbar), 468 scrollbar.theme().trackPosition(scrollbar),
459 scrollableArea->shouldPlaceVerticalScrollbarOnLeft()); 469 scrollableArea->shouldPlaceVerticalScrollbarOnLeft(), scrollLayer);
460 } else { 470 } else {
461 webScrollbarLayer = createScrollbarLayer( 471 webScrollbarLayer = createScrollbarLayer(
462 scrollbar, m_page->deviceScaleFactorDeprecated()); 472 scrollbar, m_page->deviceScaleFactorDeprecated(), scrollLayer);
463 } 473 }
464 scrollbarLayer = addWebScrollbarLayer(scrollableArea, orientation, 474 scrollbarLayer = addWebScrollbarLayer(scrollableArea, orientation,
465 std::move(webScrollbarLayer)); 475 std::move(webScrollbarLayer));
466 } 476 }
467 477
468 WebLayer* scrollLayer = toWebLayer(scrollableArea->layerForScrolling());
469 setupScrollbarLayer(scrollbarGraphicsLayer, scrollbarLayer, scrollLayer); 478 setupScrollbarLayer(scrollbarGraphicsLayer, scrollbarLayer, scrollLayer);
470 479
471 // Root layer non-overlay scrollbars should be marked opaque to disable 480 // Root layer non-overlay scrollbars should be marked opaque to disable
472 // blending. 481 // blending.
473 bool isOpaqueScrollbar = !scrollbar.isOverlayScrollbar(); 482 bool isOpaqueScrollbar = !scrollbar.isOverlayScrollbar();
474 scrollbarGraphicsLayer->setContentsOpaque(isMainFrame && isOpaqueScrollbar); 483 scrollbarGraphicsLayer->setContentsOpaque(isMainFrame && isOpaqueScrollbar);
475 } else { 484 } else {
476 removeWebScrollbarLayer(scrollableArea, orientation); 485 removeWebScrollbarLayer(scrollableArea, orientation);
477 } 486 }
478 } 487 }
(...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after
1195 frameView ? toWebLayer(frameView->layoutViewportScrollableArea() 1204 frameView ? toWebLayer(frameView->layoutViewportScrollableArea()
1196 ->layerForScrolling()) 1205 ->layerForScrolling())
1197 : nullptr) { 1206 : nullptr) {
1198 return WebSize(frameView->layoutViewportScrollableArea()->contentsSize()) != 1207 return WebSize(frameView->layoutViewportScrollableArea()->contentsSize()) !=
1199 scrollLayer->bounds(); 1208 scrollLayer->bounds();
1200 } 1209 }
1201 return false; 1210 return false;
1202 } 1211 }
1203 1212
1204 } // namespace blink 1213 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698