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

Side by Side Diff: components/exo/shell_surface.cc

Issue 2686533004: Use pixel coordinates for shadow underlay bounds (Closed)
Patch Set: remove unnecessary changes Created 3 years, 10 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 | « components/exo/shell_surface.h ('k') | components/exo/shell_surface_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/exo/shell_surface.h" 5 #include "components/exo/shell_surface.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "ash/common/frame/custom_frame_view_ash.h" 9 #include "ash/common/frame/custom_frame_view_ash.h"
10 #include "ash/common/shelf/wm_shelf.h" 10 #include "ash/common/shelf/wm_shelf.h"
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 geometry.ToString()); 585 geometry.ToString());
586 586
587 if (geometry.IsEmpty()) { 587 if (geometry.IsEmpty()) {
588 DLOG(WARNING) << "Surface geometry must be non-empty"; 588 DLOG(WARNING) << "Surface geometry must be non-empty";
589 return; 589 return;
590 } 590 }
591 591
592 pending_geometry_ = geometry; 592 pending_geometry_ = geometry;
593 } 593 }
594 594
595 void ShellSurface::SetRectangularShadow(bool enabled) { 595 void ShellSurface::SetRectangularShadowEnabled(bool enabled) {
596 TRACE_EVENT1("exo", "ShellSurface::SetRectangularShadow", "enabled", enabled); 596 TRACE_EVENT1("exo", "ShellSurface::SetRectangularShadowEnabled", "enabled",
597 597 enabled);
598 shadow_underlay_in_surface_ = false;
598 shadow_enabled_ = enabled; 599 shadow_enabled_ = enabled;
599 } 600 }
600 601
601 void ShellSurface::SetRectangularShadowContentBounds( 602 void ShellSurface::SetRectangularShadow_DEPRECATED(
602 const gfx::Rect& content_bounds) { 603 const gfx::Rect& content_bounds) {
603 TRACE_EVENT1("exo", "ShellSurface::SetRectangularShadowContentBounds", 604 TRACE_EVENT1("exo", "ShellSurface::SetRectangularShadow_DEPRECATED",
604 "content_bounds", content_bounds.ToString()); 605 "content_bounds", content_bounds.ToString());
606 shadow_underlay_in_surface_ = false;
607 shadow_content_bounds_ = content_bounds;
608 shadow_enabled_ = !content_bounds.IsEmpty();
609 }
605 610
611 void ShellSurface::SetRectangularSurfaceShadow(
612 const gfx::Rect& content_bounds) {
613 TRACE_EVENT1("exo", "ShellSurface::SetRectangularSurfaceShadow",
614 "content_bounds", content_bounds.ToString());
615 shadow_underlay_in_surface_ = true;
606 shadow_content_bounds_ = content_bounds; 616 shadow_content_bounds_ = content_bounds;
617 shadow_enabled_ = !content_bounds.IsEmpty();
607 } 618 }
608 619
609 void ShellSurface::SetRectangularShadowBackgroundOpacity(float opacity) { 620 void ShellSurface::SetRectangularShadowBackgroundOpacity(float opacity) {
610 TRACE_EVENT1("exo", "ShellSurface::SetRectangularShadowBackgroundOpacity", 621 TRACE_EVENT1("exo", "ShellSurface::SetRectangularShadowBackgroundOpacity",
611 "opacity", opacity); 622 "opacity", opacity);
612
613 shadow_background_opacity_ = opacity; 623 shadow_background_opacity_ = opacity;
614 } 624 }
615 625
616 void ShellSurface::SetFrame(bool enabled) { 626 void ShellSurface::SetFrame(bool enabled) {
617 TRACE_EVENT1("exo", "ShellSurface::SetFrame", "enabled", enabled); 627 TRACE_EVENT1("exo", "ShellSurface::SetFrame", "enabled", enabled);
618 628
619 frame_enabled_ = enabled; 629 frame_enabled_ = enabled;
620 } 630 }
621 631
622 void ShellSurface::SetScale(double scale) { 632 void ShellSurface::SetScale(double scale) {
(...skipping 784 matching lines...) Expand 10 before | Expand all | Expand 10 after
1407 void ShellSurface::UpdateShadow() { 1417 void ShellSurface::UpdateShadow() {
1408 if (!widget_) 1418 if (!widget_)
1409 return; 1419 return;
1410 aura::Window* window = widget_->GetNativeWindow(); 1420 aura::Window* window = widget_->GetNativeWindow();
1411 if (!shadow_enabled_) { 1421 if (!shadow_enabled_) {
1412 wm::SetShadowElevation(window, wm::ShadowElevation::NONE); 1422 wm::SetShadowElevation(window, wm::ShadowElevation::NONE);
1413 if (shadow_underlay_) 1423 if (shadow_underlay_)
1414 shadow_underlay_->Hide(); 1424 shadow_underlay_->Hide();
1415 } else { 1425 } else {
1416 wm::SetShadowElevation(window, wm::ShadowElevation::MEDIUM); 1426 wm::SetShadowElevation(window, wm::ShadowElevation::MEDIUM);
1427 gfx::Rect shadow_content_bounds =
1428 gfx::ScaleToEnclosedRect(shadow_content_bounds_, 1.f / scale_);
1429 gfx::Rect shadow_underlay_bounds = shadow_content_bounds_;
1430 if (shadow_underlay_bounds.IsEmpty())
1431 shadow_underlay_bounds = gfx::Rect(surface_->window()->bounds().size());
1417 1432
1418 gfx::Rect shadow_content_bounds = shadow_content_bounds_; 1433 if (!shadow_underlay_in_surface_) {
1419 if (shadow_content_bounds.IsEmpty()) 1434 shadow_content_bounds = shadow_content_bounds_;
1420 shadow_content_bounds = window->bounds(); 1435 if (shadow_content_bounds.IsEmpty()) {
1436 shadow_content_bounds = window->bounds();
1437 }
1438 }
1421 1439
1422 // TODO(oshima): Adjust the coordinates from client screen to 1440 // TODO(oshima): Adjust the coordinates from client screen to
1423 // chromeos screen when multi displays are supported. 1441 // chromeos screen when multi displays are supported.
1424 gfx::Point origin = window->bounds().origin(); 1442 gfx::Point origin = window->bounds().origin();
1425 gfx::Point shadow_origin = shadow_content_bounds.origin(); 1443 gfx::Point shadow_origin = shadow_content_bounds.origin();
1426 shadow_origin -= origin.OffsetFromOrigin(); 1444 shadow_origin -= origin.OffsetFromOrigin();
1427 gfx::Rect shadow_bounds(shadow_origin, shadow_content_bounds.size()); 1445 gfx::Rect shadow_bounds(shadow_origin, shadow_content_bounds.size());
1428 1446
1429 // Always create and show the underlay, even in maximized/fullscreen. 1447 // Always create and show the underlay, even in maximized/fullscreen.
1430 if (!shadow_underlay_) { 1448 if (!shadow_underlay_) {
1431 shadow_underlay_ = new aura::Window(nullptr); 1449 shadow_underlay_ = new aura::Window(nullptr);
1432 shadow_underlay_event_handler_ = 1450 shadow_underlay_event_handler_ =
1433 base::MakeUnique<ShadowUnderlayEventHandler>(); 1451 base::MakeUnique<ShadowUnderlayEventHandler>();
1434 shadow_underlay_->SetTargetHandler(shadow_underlay_event_handler_.get()); 1452 shadow_underlay_->SetTargetHandler(shadow_underlay_event_handler_.get());
1435 DCHECK(shadow_underlay_->owned_by_parent()); 1453 DCHECK(shadow_underlay_->owned_by_parent());
1436 // Ensure the background area inside the shadow is solid black. 1454 // Ensure the background area inside the shadow is solid black.
1437 // Clients that provide translucent contents should not be using 1455 // Clients that provide translucent contents should not be using
1438 // rectangular shadows as this method requires opaque contents to 1456 // rectangular shadows as this method requires opaque contents to
1439 // cast a shadow that represent it correctly. 1457 // cast a shadow that represent it correctly.
1440 shadow_underlay_->Init(ui::LAYER_SOLID_COLOR); 1458 shadow_underlay_->Init(ui::LAYER_SOLID_COLOR);
1441 shadow_underlay_->layer()->SetColor(SK_ColorBLACK); 1459 shadow_underlay_->layer()->SetColor(SK_ColorBLACK);
1442 DCHECK(shadow_underlay_->layer()->fills_bounds_opaquely()); 1460 DCHECK(shadow_underlay_->layer()->fills_bounds_opaquely());
1443 window->AddChild(shadow_underlay_); 1461 if (shadow_underlay_in_surface_) {
1444 window->StackChildAtBottom(shadow_underlay_); 1462 surface_->window()->AddChild(shadow_underlay_);
1463 surface_->window()->StackChildAtBottom(shadow_underlay_);
1464 } else {
1465 window->AddChild(shadow_underlay_);
1466 window->StackChildAtBottom(shadow_underlay_);
1467 }
1445 } 1468 }
1446 1469
1447 bool underlay_capture_events = 1470 bool underlay_capture_events =
1448 WMHelper::GetInstance()->IsSpokenFeedbackEnabled() && 1471 WMHelper::GetInstance()->IsSpokenFeedbackEnabled() &&
1449 widget_->IsActive(); 1472 widget_->IsActive();
1450 1473
1451 float shadow_underlay_opacity = shadow_background_opacity_; 1474 float shadow_underlay_opacity = shadow_background_opacity_;
1452 // Put the black background layer behind the window if 1475 // Put the black background layer behind the window if
1453 // 1) the window is in immersive fullscreen or is active with 1476 // 1) the window is in immersive fullscreen or is active with
1454 // spoken feedback enabled. 1477 // spoken feedback enabled.
1455 // 2) the window can control the bounds of the window in fullscreen ( 1478 // 2) the window can control the bounds of the window in fullscreen (
1456 // thus the background can be visible). 1479 // thus the background can be visible).
1457 // 3) the window has no transform (the transformed background may 1480 // 3) the window has no transform (the transformed background may
1458 // not cover the entire background, e.g. overview mode). 1481 // not cover the entire background, e.g. overview mode).
1459 if ((widget_->IsFullscreen() || underlay_capture_events) && 1482 if ((widget_->IsFullscreen() || underlay_capture_events) &&
1460 ash::wm::GetWindowState(window)->allow_set_bounds_in_maximized() && 1483 ash::wm::GetWindowState(window)->allow_set_bounds_in_maximized() &&
1461 window->layer()->GetTargetTransform().IsIdentity()) { 1484 window->layer()->GetTargetTransform().IsIdentity()) {
1462 gfx::Point origin; 1485 if (shadow_underlay_in_surface_) {
1463 origin -= window->bounds().origin().OffsetFromOrigin(); 1486 shadow_underlay_bounds = gfx::Rect(surface_->window()->bounds().size());
1464 shadow_bounds.set_origin(origin); 1487 } else {
1465 shadow_bounds.set_size(window->parent()->bounds().size()); 1488 gfx::Point origin;
1489 origin -= window->bounds().origin().OffsetFromOrigin();
1490 shadow_bounds.set_origin(origin);
1491 shadow_bounds.set_size(window->parent()->bounds().size());
1492 }
1466 shadow_underlay_opacity = 1.0f; 1493 shadow_underlay_opacity = 1.0f;
1467 } 1494 }
1468 1495
1469 gfx::Rect shadow_underlay_bounds = shadow_bounds; 1496 if (!shadow_underlay_in_surface_)
1497 shadow_underlay_bounds = shadow_bounds;
1470 1498
1471 // Constrain the underlay bounds to the client area in case shell surface 1499 // Constrain the underlay bounds to the client area in case shell surface
1472 // frame is enabled. 1500 // frame is enabled.
1473 if (frame_enabled_) { 1501 if (frame_enabled_) {
1474 shadow_underlay_bounds.Intersect( 1502 shadow_underlay_bounds.Intersect(
1475 widget_->non_client_view()->frame_view()->GetBoundsForClientView()); 1503 widget_->non_client_view()->frame_view()->GetBoundsForClientView());
1476 } 1504 }
1477 1505
1478 shadow_underlay_->SetBounds(shadow_underlay_bounds); 1506 shadow_underlay_->SetBounds(shadow_underlay_bounds);
1479 1507
(...skipping 11 matching lines...) Expand all
1491 if (!shadow) 1519 if (!shadow)
1492 return; 1520 return;
1493 1521
1494 if (!shadow_overlay_) { 1522 if (!shadow_overlay_) {
1495 shadow_overlay_ = new aura::Window(nullptr); 1523 shadow_overlay_ = new aura::Window(nullptr);
1496 DCHECK(shadow_overlay_->owned_by_parent()); 1524 DCHECK(shadow_overlay_->owned_by_parent());
1497 shadow_overlay_->set_ignore_events(true); 1525 shadow_overlay_->set_ignore_events(true);
1498 shadow_overlay_->Init(ui::LAYER_NOT_DRAWN); 1526 shadow_overlay_->Init(ui::LAYER_NOT_DRAWN);
1499 shadow_overlay_->layer()->Add(shadow->layer()); 1527 shadow_overlay_->layer()->Add(shadow->layer());
1500 window->AddChild(shadow_overlay_); 1528 window->AddChild(shadow_overlay_);
1529 if (shadow_underlay_in_surface_) {
1530 window->StackChildBelow(shadow_overlay_, surface_->window());
1531 }
1501 shadow_overlay_->Show(); 1532 shadow_overlay_->Show();
1502 } 1533 }
1503 shadow_overlay_->SetBounds(shadow_bounds); 1534 shadow_overlay_->SetBounds(shadow_bounds);
1504 shadow->SetContentBounds(gfx::Rect(shadow_bounds.size())); 1535 shadow->SetContentBounds(gfx::Rect(shadow_bounds.size()));
1505 // Surfaces that can't be activated are usually menus and tooltips. Use a 1536 // Surfaces that can't be activated are usually menus and tooltips. Use a
1506 // small style shadow for them. 1537 // small style shadow for them.
1507 if (!activatable_) 1538 if (!activatable_)
1508 shadow->SetElevation(wm::ShadowElevation::SMALL); 1539 shadow->SetElevation(wm::ShadowElevation::SMALL);
1509 } 1540 }
1510 } 1541 }
1511 1542
1512 } // namespace exo 1543 } // namespace exo
OLDNEW
« no previous file with comments | « components/exo/shell_surface.h ('k') | components/exo/shell_surface_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698