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

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

Issue 2664403004: Use pixel coordinates for shadow underlay bounds (Closed)
Patch Set: update names etc 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
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::SetRectangularShadow_DEPRECATED(
596 TRACE_EVENT1("exo", "ShellSurface::SetRectangularShadow", "enabled", enabled); 596 const gfx::Rect& content_bounds) {
597 TRACE_EVENT1("exo", "ShellSurface::SetRectangularShadow", "content_bounds",
598 content_bounds.ToString());
597 599
598 shadow_enabled_ = enabled; 600 shadow_underlay_in_shell_surface_ = false;
601 shadow_content_bounds_ = content_bounds;
602 shadow_enabled_ = !content_bounds.IsEmpty();
599 } 603 }
600 604
601 void ShellSurface::SetRectangularShadowContentBounds( 605 void ShellSurface::SetRectangularSurfaceShadow(
602 const gfx::Rect& content_bounds) { 606 const gfx::Rect& content_bounds) {
603 TRACE_EVENT1("exo", "ShellSurface::SetRectangularShadowContentBounds", 607 TRACE_EVENT1("exo", "ShellSurface::SetRectangularSurfaceShadow",
604 "content_bounds", content_bounds.ToString()); 608 "content_bounds", content_bounds.ToString());
605 609
606 shadow_content_bounds_ = content_bounds; 610 shadow_content_bounds_ = content_bounds;
611 shadow_enabled_ = !content_bounds.IsEmpty();
607 } 612 }
608 613
609 void ShellSurface::SetRectangularShadowBackgroundOpacity(float opacity) { 614 void ShellSurface::SetRectangularShadowBackgroundOpacity(float opacity) {
610 TRACE_EVENT1("exo", "ShellSurface::SetRectangularShadowBackgroundOpacity", 615 TRACE_EVENT1("exo", "ShellSurface::SetRectangularShadowBackgroundOpacity",
611 "opacity", opacity); 616 "opacity", opacity);
612 617
613 shadow_background_opacity_ = opacity; 618 shadow_background_opacity_ = opacity;
614 } 619 }
615 620
616 void ShellSurface::SetFrame(bool enabled) { 621 void ShellSurface::SetFrame(bool enabled) {
(...skipping 790 matching lines...) Expand 10 before | Expand all | Expand 10 after
1407 void ShellSurface::UpdateShadow() { 1412 void ShellSurface::UpdateShadow() {
1408 if (!widget_) 1413 if (!widget_)
1409 return; 1414 return;
1410 aura::Window* window = widget_->GetNativeWindow(); 1415 aura::Window* window = widget_->GetNativeWindow();
1411 if (!shadow_enabled_) { 1416 if (!shadow_enabled_) {
1412 wm::SetShadowElevation(window, wm::ShadowElevation::NONE); 1417 wm::SetShadowElevation(window, wm::ShadowElevation::NONE);
1413 if (shadow_underlay_) 1418 if (shadow_underlay_)
1414 shadow_underlay_->Hide(); 1419 shadow_underlay_->Hide();
1415 } else { 1420 } else {
1416 wm::SetShadowElevation(window, wm::ShadowElevation::MEDIUM); 1421 wm::SetShadowElevation(window, wm::ShadowElevation::MEDIUM);
1422 gfx::Rect shadow_content_bounds =
1423 gfx::ScaleToEnclosedRect(shadow_content_bounds_, 1.f / scale_);
1424 gfx::Rect shadow_underlay_bounds = shadow_content_bounds_;
1425 if (shadow_underlay_bounds.IsEmpty())
1426 shadow_underlay_bounds = gfx::Rect(surface_->window()->bounds().size());
1417 1427
1418 gfx::Rect shadow_content_bounds = shadow_content_bounds_; 1428 if (!shadow_underlay_in_shell_surface_) {
1419 if (shadow_content_bounds.IsEmpty()) 1429 shadow_content_bounds = shadow_content_bounds_;
1420 shadow_content_bounds = window->bounds(); 1430 if (shadow_content_bounds.IsEmpty()) {
1431 shadow_content_bounds = window->bounds();
1432 }
1433 }
1421 1434
1422 // TODO(oshima): Adjust the coordinates from client screen to 1435 // TODO(oshima): Adjust the coordinates from client screen to
1423 // chromeos screen when multi displays are supported. 1436 // chromeos screen when multi displays are supported.
1424 gfx::Point origin = window->bounds().origin(); 1437 gfx::Point origin = window->bounds().origin();
1425 gfx::Point shadow_origin = shadow_content_bounds.origin(); 1438 gfx::Point shadow_origin = shadow_content_bounds.origin();
1426 shadow_origin -= origin.OffsetFromOrigin(); 1439 shadow_origin -= origin.OffsetFromOrigin();
1427 gfx::Rect shadow_bounds(shadow_origin, shadow_content_bounds.size()); 1440 gfx::Rect shadow_bounds(shadow_origin, shadow_content_bounds.size());
1428 1441
1429 // Always create and show the underlay, even in maximized/fullscreen. 1442 // Always create and show the underlay, even in maximized/fullscreen.
1430 if (!shadow_underlay_) { 1443 if (!shadow_underlay_) {
1431 shadow_underlay_ = new aura::Window(nullptr); 1444 shadow_underlay_ = new aura::Window(nullptr);
1432 shadow_underlay_event_handler_ = 1445 shadow_underlay_event_handler_ =
1433 base::MakeUnique<ShadowUnderlayEventHandler>(); 1446 base::MakeUnique<ShadowUnderlayEventHandler>();
1434 shadow_underlay_->SetTargetHandler(shadow_underlay_event_handler_.get()); 1447 shadow_underlay_->SetTargetHandler(shadow_underlay_event_handler_.get());
1435 DCHECK(shadow_underlay_->owned_by_parent()); 1448 DCHECK(shadow_underlay_->owned_by_parent());
1436 // Ensure the background area inside the shadow is solid black. 1449 // Ensure the background area inside the shadow is solid black.
1437 // Clients that provide translucent contents should not be using 1450 // Clients that provide translucent contents should not be using
1438 // rectangular shadows as this method requires opaque contents to 1451 // rectangular shadows as this method requires opaque contents to
1439 // cast a shadow that represent it correctly. 1452 // cast a shadow that represent it correctly.
1440 shadow_underlay_->Init(ui::LAYER_SOLID_COLOR); 1453 shadow_underlay_->Init(ui::LAYER_SOLID_COLOR);
1441 shadow_underlay_->layer()->SetColor(SK_ColorBLACK); 1454 shadow_underlay_->layer()->SetColor(SK_ColorBLACK);
1442 DCHECK(shadow_underlay_->layer()->fills_bounds_opaquely()); 1455 DCHECK(shadow_underlay_->layer()->fills_bounds_opaquely());
1443 window->AddChild(shadow_underlay_); 1456 if (!shadow_underlay_in_shell_surface_) {
1444 window->StackChildAtBottom(shadow_underlay_); 1457 window->AddChild(shadow_underlay_);
1458 window->StackChildAtBottom(shadow_underlay_);
1459 } else {
1460 surface_->window()->AddChild(shadow_underlay_);
1461 }
1462 }
1463
1464 if (shadow_underlay_in_shell_surface_) {
1465 surface_->window()->StackChildAtBottom(shadow_underlay_);
1445 } 1466 }
1446 1467
1447 bool underlay_capture_events = 1468 bool underlay_capture_events =
1448 WMHelper::GetInstance()->IsSpokenFeedbackEnabled() && 1469 WMHelper::GetInstance()->IsSpokenFeedbackEnabled() &&
1449 widget_->IsActive(); 1470 widget_->IsActive();
1450 1471
1451 float shadow_underlay_opacity = shadow_background_opacity_; 1472 float shadow_underlay_opacity = shadow_background_opacity_;
1452 // Put the black background layer behind the window if 1473 // Put the black background layer behind the window if
1453 // 1) the window is in immersive fullscreen or is active with 1474 // 1) the window is in immersive fullscreen or is active with
1454 // spoken feedback enabled. 1475 // spoken feedback enabled.
1455 // 2) the window can control the bounds of the window in fullscreen ( 1476 // 2) the window can control the bounds of the window in fullscreen (
1456 // thus the background can be visible). 1477 // thus the background can be visible).
1457 // 3) the window has no transform (the transformed background may 1478 // 3) the window has no transform (the transformed background may
1458 // not cover the entire background, e.g. overview mode). 1479 // not cover the entire background, e.g. overview mode).
1459 if ((widget_->IsFullscreen() || underlay_capture_events) && 1480 if ((widget_->IsFullscreen() || underlay_capture_events) &&
1460 ash::wm::GetWindowState(window)->allow_set_bounds_in_maximized() && 1481 ash::wm::GetWindowState(window)->allow_set_bounds_in_maximized() &&
1461 window->layer()->GetTargetTransform().IsIdentity()) { 1482 window->layer()->GetTargetTransform().IsIdentity()) {
1462 gfx::Point origin; 1483 if (!shadow_underlay_in_shell_surface_) {
1463 origin -= window->bounds().origin().OffsetFromOrigin(); 1484 gfx::Point origin;
1464 shadow_bounds.set_origin(origin); 1485 origin -= window->bounds().origin().OffsetFromOrigin();
1465 shadow_bounds.set_size(window->parent()->bounds().size()); 1486 shadow_bounds.set_origin(origin);
1487 shadow_bounds.set_size(window->parent()->bounds().size());
1488 } else {
1489 shadow_underlay_bounds = gfx::Rect(surface_->window()->bounds().size());
1490 }
1466 shadow_underlay_opacity = 1.0f; 1491 shadow_underlay_opacity = 1.0f;
1467 } 1492 }
1468 1493
1469 gfx::Rect shadow_underlay_bounds = shadow_bounds; 1494 if (!shadow_underlay_in_shell_surface_)
1495 shadow_underlay_bounds = shadow_bounds;
1470 1496
1471 // Constrain the underlay bounds to the client area in case shell surface 1497 // Constrain the underlay bounds to the client area in case shell surface
1472 // frame is enabled. 1498 // frame is enabled.
1473 if (frame_enabled_) { 1499 if (frame_enabled_) {
1474 shadow_underlay_bounds.Intersect( 1500 shadow_underlay_bounds.Intersect(
1475 widget_->non_client_view()->frame_view()->GetBoundsForClientView()); 1501 widget_->non_client_view()->frame_view()->GetBoundsForClientView());
1476 } 1502 }
1477 1503
1478 shadow_underlay_->SetBounds(shadow_underlay_bounds); 1504 shadow_underlay_->SetBounds(shadow_underlay_bounds);
1479 1505
(...skipping 11 matching lines...) Expand all
1491 if (!shadow) 1517 if (!shadow)
1492 return; 1518 return;
1493 1519
1494 if (!shadow_overlay_) { 1520 if (!shadow_overlay_) {
1495 shadow_overlay_ = new aura::Window(nullptr); 1521 shadow_overlay_ = new aura::Window(nullptr);
1496 DCHECK(shadow_overlay_->owned_by_parent()); 1522 DCHECK(shadow_overlay_->owned_by_parent());
1497 shadow_overlay_->set_ignore_events(true); 1523 shadow_overlay_->set_ignore_events(true);
1498 shadow_overlay_->Init(ui::LAYER_NOT_DRAWN); 1524 shadow_overlay_->Init(ui::LAYER_NOT_DRAWN);
1499 shadow_overlay_->layer()->Add(shadow->layer()); 1525 shadow_overlay_->layer()->Add(shadow->layer());
1500 window->AddChild(shadow_overlay_); 1526 window->AddChild(shadow_overlay_);
1501 window->StackChildAbove(shadow_overlay_, shadow_underlay_); 1527
1528 if (!shadow_underlay_in_shell_surface_) {
1529 window->StackChildAbove(shadow_overlay_, shadow_underlay_);
1530 } else {
1531 window->StackChildBelow(shadow_overlay_, surface_->window());
1532 }
1502 shadow_overlay_->Show(); 1533 shadow_overlay_->Show();
1503 } 1534 }
1504 shadow_overlay_->SetBounds(shadow_bounds); 1535 shadow_overlay_->SetBounds(shadow_bounds);
1505 shadow->SetContentBounds(gfx::Rect(shadow_bounds.size())); 1536 shadow->SetContentBounds(gfx::Rect(shadow_bounds.size()));
1506 // Surfaces that can't be activated are usually menus and tooltips. Use a 1537 // Surfaces that can't be activated are usually menus and tooltips. Use a
1507 // small style shadow for them. 1538 // small style shadow for them.
1508 if (!activatable_) 1539 if (!activatable_)
1509 shadow->SetElevation(wm::ShadowElevation::SMALL); 1540 shadow->SetElevation(wm::ShadowElevation::SMALL);
1510 // We don't have rounded corners unless frame is enabled. 1541 // We don't have rounded corners unless frame is enabled.
1511 if (!frame_enabled_) 1542 if (!frame_enabled_)
1512 shadow->SetRoundedCornerRadius(0); 1543 shadow->SetRoundedCornerRadius(0);
1513 } 1544 }
1514 } 1545 }
1515 1546
1516 } // namespace exo 1547 } // namespace exo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698