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

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

Issue 2664403004: Use pixel coordinates for shadow underlay bounds (Closed)
Patch Set: . 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') | no next file » | 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 605 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 void ShellSurface::SetFrame(bool enabled) { 616 void ShellSurface::SetFrame(bool enabled) {
617 TRACE_EVENT1("exo", "ShellSurface::SetFrame", "enabled", enabled); 617 TRACE_EVENT1("exo", "ShellSurface::SetFrame", "enabled", enabled);
618 618
619 frame_enabled_ = enabled; 619 frame_enabled_ = enabled;
620 } 620 }
621 621
622 void ShellSurface::SetScale(double scale) { 622 void ShellSurface::SetScale(double scale) {
623 TRACE_EVENT1("exo", "ShellSurface::SetScale", "scale", scale); 623 TRACE_EVENT1("exo", "ShellSurface::SetScale", "scale", scale);
624 624
625 if (scale <= 0.0) { 625 if (scale <= 0.0) {
626 // TODO(oshima): This uses negative value to tell if android is
627 // NYC, which sends pixel bounds for shadow. Remove this once NYC
628 // transition is complete.
629 pixel_shadow_bounds_ = true;
630 pending_scale_ = -scale;
oshima 2017/02/02 00:05:55 I'm using negative scale during the transition. If
626 DLOG(WARNING) << "Surface scale must be greater than 0"; 631 DLOG(WARNING) << "Surface scale must be greater than 0";
627 return; 632 return;
628 } 633 }
629 634
630 pending_scale_ = scale; 635 pending_scale_ = scale;
631 } 636 }
632 637
633 void ShellSurface::SetTopInset(int height) { 638 void ShellSurface::SetTopInset(int height) {
634 TRACE_EVENT1("exo", "ShellSurface::SetTopInset", "height", height); 639 TRACE_EVENT1("exo", "ShellSurface::SetTopInset", "height", height);
635 640
(...skipping 771 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 (!pixel_shadow_bounds_) {
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 (!pixel_shadow_bounds_) {
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 (pixel_shadow_bounds_) {
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 (!pixel_shadow_bounds_) {
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 (!pixel_shadow_bounds_) {
1495 shadow_underlay_bounds = shadow_bounds;
1496 }
1470 1497
1471 // Constrain the underlay bounds to the client area in case shell surface 1498 // Constrain the underlay bounds to the client area in case shell surface
1472 // frame is enabled. 1499 // frame is enabled.
1473 if (frame_enabled_) { 1500 if (frame_enabled_) {
1474 shadow_underlay_bounds.Intersect( 1501 shadow_underlay_bounds.Intersect(
1475 widget_->non_client_view()->frame_view()->GetBoundsForClientView()); 1502 widget_->non_client_view()->frame_view()->GetBoundsForClientView());
1476 } 1503 }
1477 1504
1478 shadow_underlay_->SetBounds(shadow_underlay_bounds); 1505 shadow_underlay_->SetBounds(shadow_underlay_bounds);
1479 1506
(...skipping 11 matching lines...) Expand all
1491 if (!shadow) 1518 if (!shadow)
1492 return; 1519 return;
1493 1520
1494 if (!shadow_overlay_) { 1521 if (!shadow_overlay_) {
1495 shadow_overlay_ = new aura::Window(nullptr); 1522 shadow_overlay_ = new aura::Window(nullptr);
1496 DCHECK(shadow_overlay_->owned_by_parent()); 1523 DCHECK(shadow_overlay_->owned_by_parent());
1497 shadow_overlay_->set_ignore_events(true); 1524 shadow_overlay_->set_ignore_events(true);
1498 shadow_overlay_->Init(ui::LAYER_NOT_DRAWN); 1525 shadow_overlay_->Init(ui::LAYER_NOT_DRAWN);
1499 shadow_overlay_->layer()->Add(shadow->layer()); 1526 shadow_overlay_->layer()->Add(shadow->layer());
1500 window->AddChild(shadow_overlay_); 1527 window->AddChild(shadow_overlay_);
1501 window->StackChildAbove(shadow_overlay_, shadow_underlay_); 1528
1529 if (!pixel_shadow_bounds_) {
1530 window->StackChildAbove(shadow_overlay_, shadow_underlay_);
1531 } else {
1532 window->StackChildBelow(shadow_overlay_, surface_->window());
1533 }
1502 shadow_overlay_->Show(); 1534 shadow_overlay_->Show();
1503 } 1535 }
1504 shadow_overlay_->SetBounds(shadow_bounds); 1536 shadow_overlay_->SetBounds(shadow_bounds);
1505 shadow->SetContentBounds(gfx::Rect(shadow_bounds.size())); 1537 shadow->SetContentBounds(gfx::Rect(shadow_bounds.size()));
1506 // Surfaces that can't be activated are usually menus and tooltips. Use a 1538 // Surfaces that can't be activated are usually menus and tooltips. Use a
1507 // small style shadow for them. 1539 // small style shadow for them.
1508 if (!activatable_) 1540 if (!activatable_)
1509 shadow->SetElevation(wm::ShadowElevation::SMALL); 1541 shadow->SetElevation(wm::ShadowElevation::SMALL);
1510 // We don't have rounded corners unless frame is enabled. 1542 // We don't have rounded corners unless frame is enabled.
1511 if (!frame_enabled_) 1543 if (!frame_enabled_)
1512 shadow->SetRoundedCornerRadius(0); 1544 shadow->SetRoundedCornerRadius(0);
1513 } 1545 }
1514 } 1546 }
1515 1547
1516 } // namespace exo 1548 } // namespace exo
OLDNEW
« no previous file with comments | « components/exo/shell_surface.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698