Chromium Code Reviews| Index: ash/wm/workspace/backdrop_controller.cc |
| diff --git a/ash/wm/maximize_mode/workspace_backdrop_delegate.cc b/ash/wm/workspace/backdrop_controller.cc |
| similarity index 29% |
| rename from ash/wm/maximize_mode/workspace_backdrop_delegate.cc |
| rename to ash/wm/workspace/backdrop_controller.cc |
| index 496cc7f131de362d5e053467b6b828e1b0a40257..0ff6181900987193ef1ab1b52fde9f57a6b62baa 100644 |
| --- a/ash/wm/maximize_mode/workspace_backdrop_delegate.cc |
| +++ b/ash/wm/workspace/backdrop_controller.cc |
| @@ -2,16 +2,20 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#include "ash/wm/maximize_mode/workspace_backdrop_delegate.h" |
| +#include "ash/wm/workspace/backdrop_controller.h" |
| +#include "ash/accessibility_delegate.h" |
| #include "ash/public/cpp/shell_window_ids.h" |
| #include "ash/root_window_controller.h" |
| -#include "ash/wm/workspace/workspace_layout_manager_backdrop_delegate.h" |
| +#include "ash/shell.h" |
| +#include "ash/system/tray/system_tray_notifier.h" |
| +#include "ash/wm/workspace/backdrop_delegate.h" |
| #include "ash/wm_window.h" |
| #include "base/auto_reset.h" |
| +#include "chromeos/audio/chromeos_sounds.h" |
| +#include "ui/aura/client/aura_constants.h" |
| #include "ui/compositor/layer.h" |
| #include "ui/compositor/scoped_layer_animation_settings.h" |
| -#include "ui/views/background.h" |
| #include "ui/views/widget/widget.h" |
| #include "ui/wm/core/window_animations.h" |
| #include "ui/wm/core/window_util.h" |
| @@ -19,115 +23,205 @@ |
| namespace ash { |
| namespace { |
| -// The opacity of the backdrop. |
| -const float kBackdropOpacity = 1.0f; |
| +class BackdropEventHandler : public ui::EventHandler { |
| + public: |
| + BackdropEventHandler() {} |
|
James Cook
2017/05/15 21:57:39
nit: = default, and next line
oshima
2017/05/16 08:22:08
Done.
|
| + ~BackdropEventHandler() override {} |
| + |
| + // ui::EventHandler: |
| + void OnEvent(ui::Event* event) override { |
| + // If the event is targeted at the backdrop, it means the user has made an |
| + // interaction that is outside the window's bounds and we want to capture |
| + // it (usually when in spoken feedback mode). Handle the event (to prevent |
| + // behind-windows from receiving it) and play an earcon to notify the user. |
| + if (event->IsLocatedEvent()) { |
| + switch (event->type()) { |
| + case ui::ET_MOUSE_PRESSED: |
| + case ui::ET_MOUSEWHEEL: |
| + case ui::ET_TOUCH_PRESSED: |
| + case ui::ET_POINTER_DOWN: |
| + case ui::ET_POINTER_WHEEL_CHANGED: |
| + case ui::ET_GESTURE_BEGIN: |
| + case ui::ET_SCROLL: |
| + case ui::ET_SCROLL_FLING_START: |
| + Shell::Get()->accessibility_delegate()->PlayEarcon( |
| + chromeos::SOUND_VOLUME_ADJUST); |
| + break; |
| + default: |
| + break; |
| + } |
| + event->SetHandled(); |
| + } |
| + } |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(BackdropEventHandler); |
| +}; |
| } // namespace |
| -WorkspaceBackdropDelegate::WorkspaceBackdropDelegate(WmWindow* container) |
| +BackdropController::BackdropController(WmWindow* container) |
| : container_(container), in_restacking_(false) { |
|
James Cook
2017/05/15 21:57:38
nit: DCHECK container
oshima
2017/05/16 08:22:08
Done.
|
| - background_ = new views::Widget; |
| - views::Widget::InitParams params( |
| - views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
| - params.bounds = container_->GetBoundsInScreen(); |
| - params.layer_type = ui::LAYER_SOLID_COLOR; |
| - params.name = "WorkspaceBackdropDelegate"; |
| - // To disallow the MRU list from picking this window up it should not be |
| - // activateable. |
| - params.activatable = views::Widget::InitParams::ACTIVATABLE_NO; |
| - DCHECK_NE(kShellWindowId_Invalid, container_->aura_window()->id()); |
| - container_->GetRootWindowController()->ConfigureWidgetInitParamsForContainer( |
| - background_, container_->aura_window()->id(), ¶ms); |
| - background_->Init(params); |
| - background_window_ = WmWindow::Get(background_->GetNativeWindow()); |
| - // Do not use the animation system. We don't want the bounds animation and |
| - // opacity needs to get set to |kBackdropOpacity|. |
| - background_window_->SetVisibilityAnimationTransition(::wm::ANIMATE_NONE); |
| - background_window_->GetLayer()->SetColor(SK_ColorBLACK); |
| - // Make sure that the layer covers visibly everything - including the shelf. |
| - background_window_->GetLayer()->SetBounds(params.bounds); |
| - DCHECK(background_window_->GetBounds() == params.bounds); |
| - Show(); |
| - RestackBackdrop(); |
| -} |
| - |
| -WorkspaceBackdropDelegate::~WorkspaceBackdropDelegate() { |
| + Shell::Get()->AddShellObserver(this); |
| + Shell::Get()->system_tray_notifier()->AddAccessibilityObserver(this); |
| +} |
| + |
| +BackdropController::~BackdropController() { |
| + Shell::Get()->system_tray_notifier()->RemoveAccessibilityObserver(this); |
| + Shell::Get()->RemoveShellObserver(this); |
| // TODO: animations won't work right with mus: http://crbug.com/548396. |
| - ::wm::ScopedHidingAnimationSettings hiding_settings( |
| - background_->GetNativeView()); |
| - background_->Close(); |
| - background_window_->GetLayer()->SetOpacity(0.0f); |
| + Hide(); |
| } |
| -void WorkspaceBackdropDelegate::OnWindowAddedToLayout(WmWindow* child) { |
| - RestackBackdrop(); |
| +void BackdropController::OnWindowAddedToLayout(aura::Window* child) { |
| + UpdateBackdrop(); |
| } |
| -void WorkspaceBackdropDelegate::OnWindowRemovedFromLayout(WmWindow* child) { |
| - RestackBackdrop(); |
| +void BackdropController::OnWindowRemovedFromLayout(aura::Window* child) { |
| + UpdateBackdrop(); |
| } |
| -void WorkspaceBackdropDelegate::OnChildWindowVisibilityChanged(WmWindow* child, |
| - bool visible) { |
| - RestackBackdrop(); |
| +void BackdropController::OnChildWindowVisibilityChanged(aura::Window* child, |
| + bool visible) { |
| + UpdateBackdrop(); |
| } |
| -void WorkspaceBackdropDelegate::OnWindowStackingChanged(WmWindow* window) { |
| - RestackBackdrop(); |
| +void BackdropController::OnWindowStackingChanged(aura::Window* window) { |
| + UpdateBackdrop(); |
| } |
| -void WorkspaceBackdropDelegate::OnPostWindowStateTypeChange( |
| +void BackdropController::OnPostWindowStateTypeChange( |
| wm::WindowState* window_state, |
| wm::WindowStateType old_type) { |
| - RestackBackdrop(); |
| + UpdateBackdrop(); |
| +} |
| + |
| +void BackdropController::SetBackdropDelegate( |
| + std::unique_ptr<BackdropDelegate> delegate) { |
| + delegate_ = std::move(delegate); |
| + UpdateBackdrop(); |
| } |
| -void WorkspaceBackdropDelegate::RestackBackdrop() { |
| +void BackdropController::UpdateBackdrop() { |
| // Avoid recursive calls. |
| - if (in_restacking_) |
| + if (in_restacking_ || force_hidden_) |
| return; |
| - WmWindow* window = GetCurrentTopWindow(); |
| + aura::Window* window = GetTopmostWindowWithBackdrop(); |
| if (!window) { |
| // Hide backdrop since no suitable window was found. |
| - background_->Hide(); |
| + Hide(); |
| return; |
| } |
| - if (window == background_window_ && background_->IsVisible()) |
| - return; |
| - if (window->GetRootWindow() != background_window_->GetRootWindow()) |
| - return; |
| // We are changing the order of windows which will cause recursion. |
| base::AutoReset<bool> lock(&in_restacking_, true); |
| - if (!background_->IsVisible()) |
| + EnsureBackdropWidget(); |
| + |
| + if (window == backdrop_window_ && backdrop_->IsVisible()) |
| + return; |
| + if (window->GetRootWindow() != backdrop_window_->GetRootWindow()) |
| + return; |
| + |
| + if (!backdrop_->IsVisible()) |
| Show(); |
| // Since the backdrop needs to be immediately behind the window and the |
|
James Cook
2017/05/15 21:57:38
nit: blank line above
oshima
2017/05/16 08:22:08
Done.
|
| // stacking functions only guarantee a "it's above or below", we need |
| // to re-arrange the two windows twice. |
| - container_->StackChildAbove(background_window_, window); |
| - container_->StackChildAbove(window, background_window_); |
| + container_->aura_window()->StackChildAbove(backdrop_window_, window); |
| + container_->aura_window()->StackChildAbove(window, backdrop_window_); |
| +} |
| + |
| +void BackdropController::OnOverviewModeStarting() { |
| + force_hidden_ = true; |
| + Hide(); |
| +} |
| + |
| +void BackdropController::OnOverviewModeEnded() { |
| + force_hidden_ = false; |
| + UpdateBackdrop(); |
| +} |
| + |
| +void BackdropController::OnAccessibilityModeChanged( |
| + AccessibilityNotificationVisibility notify) { |
| + UpdateAccessibilityMode(); |
| } |
| -WmWindow* WorkspaceBackdropDelegate::GetCurrentTopWindow() { |
| +void BackdropController::EnsureBackdropWidget() { |
| + if (backdrop_) |
| + return; |
| + backdrop_ = new views::Widget; |
| + views::Widget::InitParams params( |
| + views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
| + params.bounds = container_->GetBoundsInScreen(); |
| + params.layer_type = ui::LAYER_SOLID_COLOR; |
| + params.name = "WorkspaceBackdropDelegate"; |
| + // To disallow the MRU list from picking this window up it should not be |
| + // activateable. |
| + params.activatable = views::Widget::InitParams::ACTIVATABLE_NO; |
| + DCHECK_NE(kShellWindowId_Invalid, container_->aura_window()->id()); |
| + container_->GetRootWindowController()->ConfigureWidgetInitParamsForContainer( |
| + backdrop_, container_->aura_window()->id(), ¶ms); |
| + backdrop_->Init(params); |
| + backdrop_window_ = backdrop_->GetNativeWindow(); |
| + backdrop_window_->SetName("Backdrop"); |
| + ::wm::SetWindowVisibilityAnimationType( |
| + backdrop_window_, ::wm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE); |
| + backdrop_window_->layer()->SetColor(SK_ColorBLACK); |
| + |
| + UpdateAccessibilityMode(); |
| +} |
| + |
| +void BackdropController::UpdateAccessibilityMode() { |
| + if (!backdrop_) { |
| + return; |
| + } |
|
James Cook
2017/05/15 21:57:38
nit: no {
oshima
2017/05/16 08:22:08
Done.
|
| + |
| + bool enabled = |
| + Shell::Get()->accessibility_delegate()->IsSpokenFeedbackEnabled(); |
| + if (enabled) { |
| + if (!backdrop_event_handler_) { |
| + backdrop_event_handler_ = base::MakeUnique<BackdropEventHandler>(); |
| + original_event_handler_ = |
| + backdrop_window_->SetTargetHandler(backdrop_event_handler_.get()); |
| + } |
| + } else if (backdrop_event_handler_) { |
| + backdrop_window_->SetTargetHandler(original_event_handler_); |
| + backdrop_event_handler_.reset(); |
| + } |
| +} |
| + |
| +aura::Window* BackdropController::GetTopmostWindowWithBackdrop() { |
| const WmWindow::Windows windows = container_->GetChildren(); |
| for (auto window_iter = windows.rbegin(); window_iter != windows.rend(); |
| ++window_iter) { |
| WmWindow* window = *window_iter; |
| - if (window->GetTargetVisibility() && |
| + if (window->aura_window() != backdrop_window_ && |
| + window->GetTargetVisibility() && |
| window->GetType() == ui::wm::WINDOW_TYPE_NORMAL && |
| - window->CanActivate()) |
| - return window; |
| + window->CanActivate() && |
| + ((window->aura_window()->GetAllPropertyKeys().count( |
| + aura::client::kHasBackdrop) && |
| + window->aura_window()->GetProperty(aura::client::kHasBackdrop)) || |
| + (delegate_ ? delegate_->HasBackdrop(window) : false))) { |
|
James Cook
2017/05/15 21:57:38
This conditional is really long. Can you break it
oshima
2017/05/16 08:22:08
Done.
|
| + return window->aura_window(); |
| + } |
| } |
| return nullptr; |
| } |
| -void WorkspaceBackdropDelegate::Show() { |
| - background_window_->GetLayer()->SetOpacity(0.0f); |
| - background_->Show(); |
| - background_->SetFullscreen(true); |
| - ui::ScopedLayerAnimationSettings settings( |
| - background_window_->GetLayer()->GetAnimator()); |
| - background_window_->GetLayer()->SetOpacity(kBackdropOpacity); |
| +void BackdropController::Show() { |
| + backdrop_->Show(); |
| + backdrop_->SetFullscreen(true); |
| +} |
| + |
| +void BackdropController::Hide() { |
| + if (backdrop_) { |
|
James Cook
2017/05/15 21:57:38
nit: if (!backdrop_) return;
oshima
2017/05/16 08:22:08
Done.
|
| + backdrop_->Close(); |
| + backdrop_ = nullptr; |
| + backdrop_window_ = nullptr; |
| + original_event_handler_ = nullptr; |
| + backdrop_event_handler_.reset(); |
| + } |
| } |
| } // namespace ash |