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

Unified Diff: ash/shelf/shelf_widget.cc

Issue 2190773003: [ABANDONED] Simplify ash shelf dimmer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Restore an EventHandler object; fix behavior tests. Created 4 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ash/shelf/shelf_widget.h ('k') | ui/views/widget/drop_helper.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ash/shelf/shelf_widget.cc
diff --git a/ash/shelf/shelf_widget.cc b/ash/shelf/shelf_widget.cc
index 0b986a38b947c47dc1f83a0c9218f75998244855..30773f212cd34aa830ab848f3bc165e8785cadb8 100644
--- a/ash/shelf/shelf_widget.cc
+++ b/ash/shelf/shelf_widget.cc
@@ -6,233 +6,50 @@
#include "ash/aura/wm_shelf_aura.h"
#include "ash/aura/wm_window_aura.h"
-#include "ash/common/ash_switches.h"
#include "ash/common/focus_cycler.h"
#include "ash/common/material_design/material_design_controller.h"
#include "ash/common/session/session_state_delegate.h"
#include "ash/common/shelf/shelf_constants.h"
#include "ash/common/shelf/shelf_delegate.h"
-#include "ash/common/shelf/shelf_model.h"
#include "ash/common/shelf/wm_shelf_util.h"
-#include "ash/common/shell_window_ids.h"
#include "ash/common/system/status_area_widget.h"
#include "ash/common/system/tray/system_tray_delegate.h"
+#include "ash/common/wm_lookup.h"
#include "ash/common/wm_root_window_controller.h"
#include "ash/common/wm_shell.h"
#include "ash/shelf/shelf.h"
#include "ash/shelf/shelf_layout_manager.h"
-#include "ash/shelf/shelf_util.h"
-#include "ash/shelf/shelf_view.h"
#include "ash/shell.h"
#include "ash/wm/status_area_layout_manager.h"
-#include "ash/wm/window_properties.h"
#include "ash/wm/workspace_controller.h"
#include "grit/ash_resources.h"
#include "ui/aura/window.h"
-#include "ui/aura/window_event_dispatcher.h"
-#include "ui/aura/window_observer.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/compositor/layer.h"
#include "ui/compositor/scoped_layer_animation_settings.h"
-#include "ui/events/event_constants.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/image/image.h"
#include "ui/gfx/image/image_skia_operations.h"
#include "ui/gfx/skbitmap_operations.h"
#include "ui/views/accessible_pane_view.h"
+#include "ui/events/event_handler.h"
#include "ui/views/layout/fill_layout.h"
+#include "ui/views/pointer_watcher.h"
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_delegate.h"
-#include "ui/wm/core/coordinate_conversion.h"
#include "ui/wm/core/easy_resize_window_targeter.h"
-#include "ui/wm/public/activation_client.h"
namespace ash {
namespace {
// Size of black border at bottom (or side) of shelf.
const int kNumBlackPixels = 3;
-// Alpha to paint dimming image with.
-const int kDimAlpha = 128;
-// The time to dim and un-dim.
+// The time to dim and un-dim, and the opacities used for dimming.
const int kTimeToDimMs = 3000; // Slow in dimming.
const int kTimeToUnDimMs = 200; // Fast in activating.
-
-// Class used to slightly dim shelf items when maximized and visible.
-class DimmerView : public views::View,
- public views::WidgetDelegate,
- BackgroundAnimatorDelegate {
- public:
- // If |disable_dimming_animations_for_test| is set, all alpha animations will
- // be performed instantly.
- DimmerView(ShelfWidget* shelf_widget,
- bool disable_dimming_animations_for_test);
- ~DimmerView() override;
-
- // Called by |DimmerEventFilter| when the mouse |hovered| state changes.
- void SetHovered(bool hovered);
-
- // Force the dimmer to be undimmed.
- void ForceUndimming(bool force);
-
- // views::WidgetDelegate overrides:
- views::Widget* GetWidget() override { return View::GetWidget(); }
- const views::Widget* GetWidget() const override { return View::GetWidget(); }
-
- // BackgroundAnimatorDelegate overrides:
- void UpdateBackground(int alpha) override {
- alpha_ = alpha;
- SchedulePaint();
- }
-
- // views::View overrides:
- void OnPaintBackground(gfx::Canvas* canvas) override;
-
- // A function to test the current alpha used.
- int get_dimming_alpha_for_test() { return alpha_; }
-
- private:
- // This class monitors mouse events to see if it is on top of the shelf.
- class DimmerEventFilter : public ui::EventHandler {
- public:
- explicit DimmerEventFilter(DimmerView* owner);
- ~DimmerEventFilter() override;
-
- // Overridden from ui::EventHandler:
- void OnMouseEvent(ui::MouseEvent* event) override;
- void OnTouchEvent(ui::TouchEvent* event) override;
-
- private:
- // The owning class.
- DimmerView* owner_;
-
- // TRUE if the mouse is inside the shelf.
- bool mouse_inside_;
-
- // TRUE if a touch event is inside the shelf.
- bool touch_inside_;
-
- DISALLOW_COPY_AND_ASSIGN(DimmerEventFilter);
- };
-
- // The owning shelf widget.
- ShelfWidget* shelf_;
-
- // The alpha to use for covering the shelf.
- int alpha_;
-
- // True if the event filter claims that we should not be dimmed.
- bool is_hovered_;
-
- // True if someone forces us not to be dimmed (e.g. a menu is open).
- bool force_hovered_;
-
- // True if animations should be suppressed for a test.
- bool disable_dimming_animations_for_test_;
-
- // The animator for the background transitions.
- BackgroundAnimator background_animator_;
-
- // Notification of entering / exiting of the shelf area by mouse.
- std::unique_ptr<DimmerEventFilter> event_filter_;
-
- DISALLOW_COPY_AND_ASSIGN(DimmerView);
-};
-
-DimmerView::DimmerView(ShelfWidget* shelf_widget,
- bool disable_dimming_animations_for_test)
- : shelf_(shelf_widget),
- alpha_(kDimAlpha),
- is_hovered_(false),
- force_hovered_(false),
- disable_dimming_animations_for_test_(disable_dimming_animations_for_test),
- background_animator_(this, 0, kDimAlpha) {
- event_filter_.reset(new DimmerEventFilter(this));
- // Make sure it is undimmed at the beginning and then fire off the dimming
- // animation.
- background_animator_.SetPaintsBackground(false, BACKGROUND_CHANGE_IMMEDIATE);
- SetHovered(false);
-}
-
-DimmerView::~DimmerView() {}
-
-void DimmerView::SetHovered(bool hovered) {
- // Remember the hovered state so that we can correct the state once a
- // possible force state has disappeared.
- is_hovered_ = hovered;
- // Undimm also if we were forced to by e.g. an open menu.
- hovered |= force_hovered_;
- background_animator_.SetDuration(hovered ? kTimeToUnDimMs : kTimeToDimMs);
- background_animator_.SetPaintsBackground(!hovered,
- disable_dimming_animations_for_test_
- ? BACKGROUND_CHANGE_IMMEDIATE
- : BACKGROUND_CHANGE_ANIMATE);
-}
-
-void DimmerView::ForceUndimming(bool force) {
- bool previous = force_hovered_;
- force_hovered_ = force;
- // If the forced change does change the result we apply the change.
- if (is_hovered_ || force_hovered_ != is_hovered_ || previous)
- SetHovered(is_hovered_);
-}
-
-void DimmerView::OnPaintBackground(gfx::Canvas* canvas) {
- SkPaint paint;
- ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
- gfx::ImageSkia shelf_background =
- *rb->GetImageNamed(IDR_ASH_SHELF_DIMMING).ToImageSkia();
-
- if (!IsHorizontalAlignment(shelf_->GetAlignment())) {
- shelf_background = gfx::ImageSkiaOperations::CreateRotatedImage(
- shelf_background, shelf_->GetAlignment() == SHELF_ALIGNMENT_LEFT
- ? SkBitmapOperations::ROTATION_90_CW
- : SkBitmapOperations::ROTATION_270_CW);
- }
- paint.setAlpha(alpha_);
- canvas->DrawImageInt(shelf_background, 0, 0, shelf_background.width(),
- shelf_background.height(), 0, 0, width(), height(),
- false, paint);
-}
-
-DimmerView::DimmerEventFilter::DimmerEventFilter(DimmerView* owner)
- : owner_(owner), mouse_inside_(false), touch_inside_(false) {
- Shell::GetInstance()->AddPreTargetHandler(this);
-}
-
-DimmerView::DimmerEventFilter::~DimmerEventFilter() {
- Shell::GetInstance()->RemovePreTargetHandler(this);
-}
-
-void DimmerView::DimmerEventFilter::OnMouseEvent(ui::MouseEvent* event) {
- if (event->type() != ui::ET_MOUSE_MOVED &&
- event->type() != ui::ET_MOUSE_DRAGGED)
- return;
-
- gfx::Point screen_point(event->location());
- ::wm::ConvertPointToScreen(static_cast<aura::Window*>(event->target()),
- &screen_point);
- bool inside = owner_->GetBoundsInScreen().Contains(screen_point);
- if (mouse_inside_ || touch_inside_ != inside || touch_inside_)
- owner_->SetHovered(inside || touch_inside_);
- mouse_inside_ = inside;
-}
-
-void DimmerView::DimmerEventFilter::OnTouchEvent(ui::TouchEvent* event) {
- bool touch_inside = false;
- if (event->type() != ui::ET_TOUCH_RELEASED &&
- event->type() != ui::ET_TOUCH_CANCELLED) {
- gfx::Point screen_point(event->location());
- ::wm::ConvertPointToScreen(static_cast<aura::Window*>(event->target()),
- &screen_point);
- touch_inside = owner_->GetBoundsInScreen().Contains(screen_point);
- }
-
- if (mouse_inside_ || touch_inside_ != mouse_inside_ || touch_inside)
- owner_->SetHovered(mouse_inside_ || touch_inside);
- touch_inside_ = touch_inside;
-}
+const float kDimOpactiy = 0.25f;
+const float kUnDimOpactiy = 0.0f;
// ShelfWindowTargeter makes it easier to resize windows with the mouse when the
// window-edge slightly overlaps with the shelf edge. The targeter also makes it
@@ -292,29 +109,82 @@ class ShelfWindowTargeter : public ::wm::EasyResizeWindowTargeter,
DISALLOW_COPY_AND_ASSIGN(ShelfWindowTargeter);
};
+class ShelfDimmer : public ui::EventHandler, public views::PointerWatcher {
+ public:
+ explicit ShelfDimmer(ShelfWidget* shelf) : shelf_widget_(shelf) {
+ // TODO(msw): Need to do the same for the status area widget...
+ WmWindow* window = WmLookup::Get()->GetWindowForWidget(shelf_widget_);
+ window->AddLimitedPreTargetHandler(this);
+ window = WmLookup::Get()->GetWindowForWidget(shelf_widget_->status_area_widget());
+ window->AddLimitedPreTargetHandler(this);
+ WmShell::Get()->AddPointerWatcher(this);
+ }
+
+ ~ShelfDimmer() override {
+ // TODO(msw): Remove the pre-target handler(s)...
+ WmWindow* window = WmLookup::Get()->GetWindowForWidget(shelf_widget_);
+ window->RemoveLimitedPreTargetHandler(this);
+ window = WmLookup::Get()->GetWindowForWidget(shelf_widget_->status_area_widget());
+ window->RemoveLimitedPreTargetHandler(this);
+ WmShell::Get()->RemovePointerWatcher(this);
+ }
+
+ // ui::EventHandler:
+ void OnMouseEvent(ui::MouseEvent* event) override {
+ LOG(ERROR) << "MSW ShelfDimmer OnMouseEvent " << event->name();
+ shelf_widget_->SetDimsShelf(
+ event->type() == ui::ET_MOUSE_EXITED ||
+ (event->type() == ui::ET_MOUSE_RELEASED &&
+ !shelf_widget_->GetRootView()->bounds().Contains(event->location())));
+ }
+ void OnTouchEvent(ui::TouchEvent* event) override {
+ LOG(ERROR) << "MSW ShelfDimmer OnTouchEvent " << event->name();
+ if (event->type() != ui::ET_TOUCH_PRESSED)
+ shelf_widget_->SetDimsShelf(event->type() != ui::ET_TOUCH_MOVED);
+ }
+
+ // views::PointerWatcher:
+ void OnMousePressed(const ui::MouseEvent& event,
+ const gfx::Point& location_in_screen,
+ views::Widget* target) override {}
+ void OnTouchPressed(const ui::TouchEvent& event,
+ const gfx::Point& location_in_screen,
+ views::Widget* target) override {
+ LOG(ERROR) << "MSW ShelfDimmer::OnTouchPressed " << event.name();
+ shelf_widget_->SetDimsShelf(
+ !shelf_widget_->GetWindowBoundsInScreen().Contains(location_in_screen));
+ }
+
+ private:
+ ShelfWidget* shelf_widget_;
+
+ DISALLOW_COPY_AND_ASSIGN(ShelfDimmer);
+};
+
} // namespace
// The contents view of the Shelf. This view contains ShelfView and
// sizes it to the width of the shelf minus the size of the status area.
class ShelfWidget::DelegateView : public views::WidgetDelegate,
public views::AccessiblePaneView,
- public BackgroundAnimatorDelegate,
- public aura::WindowObserver {
+ public BackgroundAnimatorDelegate {
public:
explicit DelegateView(ShelfWidget* shelf);
~DelegateView() override;
- void set_focus_cycler(FocusCycler* focus_cycler) {
- focus_cycler_ = focus_cycler;
- }
+ void set_focus_cycler(FocusCycler* cycler) { focus_cycler_ = cycler; }
FocusCycler* focus_cycler() { return focus_cycler_; }
ui::Layer* opaque_background() { return &opaque_background_; }
ui::Layer* opaque_foreground() { return &opaque_foreground_; }
- // Set if the shelf area is dimmed (eg when a window is maximized).
+ // Set if the shelf is dimmed (eg. when a window is maximized).
void SetDimmed(bool dimmed);
- bool GetDimmed() const;
+
+ // Used to initialize or shutdown the dimmer.
+ void set_dimmer(std::unique_ptr<ShelfDimmer> dimmer) {
+ shelf_dimmer_ = std::move(dimmer);
+ }
void SetParentLayer(ui::Layer* layer);
@@ -330,64 +200,36 @@ class ShelfWidget::DelegateView : public views::WidgetDelegate,
// This will be called when the parent local bounds change.
void OnBoundsChanged(const gfx::Rect& old_bounds) override;
- // aura::WindowObserver overrides:
- // This will be called when the shelf itself changes its absolute position.
- // Since the |dimmer_| panel needs to be placed in screen coordinates it needs
- // to be repositioned. The difference to the OnBoundsChanged call above is
- // that this gets also triggered when the shelf only moves.
- void OnWindowBoundsChanged(aura::Window* window,
- const gfx::Rect& old_bounds,
- const gfx::Rect& new_bounds) override;
-
// BackgroundAnimatorDelegate overrides:
void UpdateBackground(int alpha) override;
// Force the shelf to be presented in an undimmed state.
void ForceUndimming(bool force);
- // A function to test the current alpha used by the dimming bar. If there is
- // no dimmer active, the function will return -1.
- int GetDimmingAlphaForTest();
-
- // A function to test the bounds of the dimming bar. Returns gfx::Rect() if
- // the dimmer is inactive.
- gfx::Rect GetDimmerBoundsForTest();
-
- // Disable dimming animations for running tests. This needs to be called
- // prior to the creation of of the |dimmer_|.
- void disable_dimming_animations_for_test() {
- disable_dimming_animations_for_test_ = true;
- }
+ // Set the shelf dimming |opacity| over the |animation_time_ms| duration.
+ void SetShelfDimming(float opacity, int animation_time_ms);
private:
ShelfWidget* shelf_;
- std::unique_ptr<views::Widget> dimmer_;
- FocusCycler* focus_cycler_;
- int alpha_;
- // A black background layer which is shown when a maximized window is visible.
+ FocusCycler* focus_cycler_ = nullptr;
+ int alpha_ = 0;
+ // A black background shown when a maximized window is visible.
ui::Layer opaque_background_;
- // A black foreground layer which is shown while transitioning between users.
- // Note: Since the back- and foreground layers have different functions they
- // can be used simultaneously - so no repurposing possible.
+ // A black foreground shown during user transitions; also used to dim shelf
+ // items when a maximized window is visible and the shelf is not hovered.
ui::Layer opaque_foreground_;
- // The view which does the dimming.
- DimmerView* dimmer_view_;
-
- // True if dimming animations should be turned off.
- bool disable_dimming_animations_for_test_;
+ std::unique_ptr<ShelfDimmer> shelf_dimmer_;
+ bool force_dimmer_off_ = false;
+ float stored_dimmer_opacity_ = 0.0f;
DISALLOW_COPY_AND_ASSIGN(DelegateView);
};
ShelfWidget::DelegateView::DelegateView(ShelfWidget* shelf)
: shelf_(shelf),
- focus_cycler_(NULL),
- alpha_(0),
opaque_background_(ui::LAYER_SOLID_COLOR),
- opaque_foreground_(ui::LAYER_SOLID_COLOR),
- dimmer_view_(NULL),
- disable_dimming_animations_for_test_(false) {
+ opaque_foreground_(ui::LAYER_SOLID_COLOR) {
SetLayoutManager(new views::FillLayout());
set_allow_deactivate_on_esc(true);
opaque_background_.SetColor(SK_ColorBLACK);
@@ -398,45 +240,15 @@ ShelfWidget::DelegateView::DelegateView(ShelfWidget* shelf)
opaque_foreground_.SetOpacity(0.0f);
}
-ShelfWidget::DelegateView::~DelegateView() {
- // Make sure that the dimmer goes away since it might have set an observer.
- SetDimmed(false);
-}
-
-void ShelfWidget::DelegateView::SetDimmed(bool value) {
- if (value == (dimmer_.get() != NULL))
- return;
-
- if (value) {
- dimmer_.reset(new views::Widget);
- views::Widget::InitParams params(
- views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
- params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
- params.activatable = views::Widget::InitParams::ACTIVATABLE_NO;
- params.accept_events = false;
- params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
- params.parent = shelf_->GetNativeView();
- dimmer_->Init(params);
- dimmer_->GetNativeWindow()->SetName("ShelfDimmer");
- dimmer_->SetBounds(shelf_->GetWindowBoundsInScreen());
- // The shelf should not take focus when it is initially shown.
- dimmer_->set_focus_on_creation(false);
- dimmer_view_ = new DimmerView(shelf_, disable_dimming_animations_for_test_);
- dimmer_->SetContentsView(dimmer_view_);
- dimmer_->GetNativeView()->SetName("ShelfDimmerView");
- dimmer_->Show();
- shelf_->GetNativeView()->AddObserver(this);
- } else {
- // Some unit tests will come here with a destroyed window.
- if (shelf_->GetNativeView())
- shelf_->GetNativeView()->RemoveObserver(this);
- dimmer_view_ = NULL;
- dimmer_.reset(NULL);
- }
-}
+ShelfWidget::DelegateView::~DelegateView() {}
-bool ShelfWidget::DelegateView::GetDimmed() const {
- return dimmer_.get() && dimmer_->IsVisible();
+void ShelfWidget::DelegateView::SetDimmed(bool dimmed) {
+ if (force_dimmer_off_)
+ stored_dimmer_opacity_ = dimmed ? kDimOpactiy : kUnDimOpactiy;
+ else if (dimmed)
+ SetShelfDimming(kDimOpactiy, kTimeToDimMs);
+ else
+ SetShelfDimming(kUnDimOpactiy, kTimeToUnDimMs);
}
void ShelfWidget::DelegateView::SetParentLayer(ui::Layer* layer) {
@@ -524,40 +336,34 @@ void ShelfWidget::DelegateView::ReorderChildLayers(ui::Layer* parent_layer) {
void ShelfWidget::DelegateView::OnBoundsChanged(const gfx::Rect& old_bounds) {
opaque_background_.SetBounds(GetLocalBounds());
opaque_foreground_.SetBounds(GetLocalBounds());
- if (dimmer_)
- dimmer_->SetBounds(GetBoundsInScreen());
}
-void ShelfWidget::DelegateView::OnWindowBoundsChanged(
- aura::Window* window,
- const gfx::Rect& old_bounds,
- const gfx::Rect& new_bounds) {
- // Coming here the shelf got repositioned and since the |dimmer_| is placed
- // in screen coordinates and not relative to the parent it needs to be
- // repositioned accordingly.
- dimmer_->SetBounds(GetBoundsInScreen());
+void ShelfWidget::DelegateView::UpdateBackground(int alpha) {
+ alpha_ = alpha;
+ SchedulePaint();
}
void ShelfWidget::DelegateView::ForceUndimming(bool force) {
- if (GetDimmed())
- dimmer_view_->ForceUndimming(force);
+ force_dimmer_off_ = force;
+ if (force)
+ stored_dimmer_opacity_ = opaque_foreground_.opacity();
+ opaque_foreground_.SetOpacity(force ? kUnDimOpactiy : stored_dimmer_opacity_);
}
-int ShelfWidget::DelegateView::GetDimmingAlphaForTest() {
- if (GetDimmed())
- return dimmer_view_->get_dimming_alpha_for_test();
- return -1;
-}
+void ShelfWidget::DelegateView::SetShelfDimming(float opacity,
+ int animation_time_ms) {
+ if (opaque_foreground_.GetTargetOpacity() == opacity)
+ return;
-gfx::Rect ShelfWidget::DelegateView::GetDimmerBoundsForTest() {
- if (GetDimmed())
- return dimmer_view_->GetBoundsInScreen();
- return gfx::Rect();
-}
+ std::unique_ptr<ui::ScopedLayerAnimationSettings> opaque_foreground_animation;
+ opaque_foreground_animation.reset(
+ new ui::ScopedLayerAnimationSettings(opaque_foreground_.GetAnimator()));
+ opaque_foreground_animation->SetTransitionDuration(
+ base::TimeDelta::FromMilliseconds(animation_time_ms));
+ opaque_foreground_animation->SetPreemptionStrategy(
+ ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
-void ShelfWidget::DelegateView::UpdateBackground(int alpha) {
- alpha_ = alpha;
- SchedulePaint();
+ opaque_foreground_.SetOpacity(opacity);
}
ShelfWidget::ShelfWidget(WmWindow* wm_shelf_container,
@@ -611,6 +417,8 @@ ShelfWidget::ShelfWidget(WmWindow* wm_shelf_container,
status_container->SetEventTargeter(std::unique_ptr<ui::EventTargeter>(
new ShelfWindowTargeter(status_container, shelf_layout_manager_)));
+ delegate_view_->set_dimmer(base::MakeUnique<ShelfDimmer>(this));
+
views::Widget::AddObserver(this);
}
@@ -642,6 +450,10 @@ void ShelfWidget::SetPaintsBackground(
// See also DockedBackgroundWidget::SetPaintsBackground.
background_animator_.SetPaintsBackground(
background_type != SHELF_BACKGROUND_DEFAULT, change_type);
+
+ // Start or stop dimming as appropriate.
+ LOG(ERROR) << "MSW SetPaintsBackground this:" << this << " max:" << (background_type == SHELF_BACKGROUND_MAXIMIZED);
+ SetDimsShelf(background_type == SHELF_BACKGROUND_MAXIMIZED);
}
ShelfBackgroundType ShelfWidget::GetBackgroundType() const {
@@ -654,24 +466,11 @@ ShelfBackgroundType ShelfWidget::GetBackgroundType() const {
}
void ShelfWidget::HideShelfBehindBlackBar(bool hide, int animation_time_ms) {
- if (IsShelfHiddenBehindBlackBar() == hide)
- return;
-
- ui::Layer* opaque_foreground = delegate_view_->opaque_foreground();
- float target_opacity = hide ? 1.0f : 0.0f;
- std::unique_ptr<ui::ScopedLayerAnimationSettings> opaque_foreground_animation;
- opaque_foreground_animation.reset(
- new ui::ScopedLayerAnimationSettings(opaque_foreground->GetAnimator()));
- opaque_foreground_animation->SetTransitionDuration(
- base::TimeDelta::FromMilliseconds(animation_time_ms));
- opaque_foreground_animation->SetPreemptionStrategy(
- ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS);
-
- opaque_foreground->SetOpacity(target_opacity);
+ delegate_view_->SetShelfDimming(hide ? 1.0f : 0.0f, animation_time_ms);
}
bool ShelfWidget::IsShelfHiddenBehindBlackBar() const {
- return delegate_view_->opaque_foreground()->GetTargetOpacity() != 0.0f;
+ return delegate_view_->opaque_foreground()->GetTargetOpacity() == 1.0f;
}
// static
@@ -712,6 +511,15 @@ void ShelfWidget::OnShelfAlignmentChanged() {
}
void ShelfWidget::SetDimsShelf(bool dimming) {
+ LOG(ERROR) << "MSW SetDimsShelf A " << dimming;
+ // The shelf can only be dimmed when shown and the background is maximized.
+ dimming &= (GetBackgroundType() == SHELF_BACKGROUND_MAXIMIZED && shelf_ &&
+ shelf_->auto_hide_behavior() == SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
+
+ // Dimming is not possible nor useful when hidden behind a black bar.
+ if (IsShelfHiddenBehindBlackBar() || GetDimsShelf() == dimming)
+ return;
+
delegate_view_->SetDimmed(dimming);
// Repaint all children, allowing updates to reflect dimmed state eg:
// status area background, app list button and overflow button.
@@ -721,7 +529,7 @@ void ShelfWidget::SetDimsShelf(bool dimming) {
}
bool ShelfWidget::GetDimsShelf() const {
- return delegate_view_->GetDimmed();
+ return delegate_view_->opaque_foreground()->GetTargetOpacity() == kDimOpactiy;
}
void ShelfWidget::CreateShelf(WmShelfAura* wm_shelf_aura) {
@@ -764,6 +572,8 @@ FocusCycler* ShelfWidget::GetFocusCycler() {
}
void ShelfWidget::Shutdown() {
+ delegate_view_->set_dimmer(nullptr);
+
// Shutting down the status area widget may cause some widgets (e.g. bubbles)
// to close, so uninstall the ShelfLayoutManager event filters first. Don't
// reset the pointer until later because other widgets (e.g. app list) may
@@ -791,26 +601,19 @@ void ShelfWidget::OnWidgetActivationChanged(views::Widget* widget,
delegate_view_->GetFocusManager()->ClearFocus();
}
-int ShelfWidget::GetDimmingAlphaForTest() {
- if (delegate_view_)
- return delegate_view_->GetDimmingAlphaForTest();
- return -1;
-}
-
-gfx::Rect ShelfWidget::GetDimmerBoundsForTest() {
- if (delegate_view_)
- return delegate_view_->GetDimmerBoundsForTest();
- return gfx::Rect();
+void ShelfWidget::WillDeleteShelfLayoutManager() {
+ shelf_layout_manager_->RemoveObserver(this);
+ shelf_layout_manager_ = NULL;
}
-void ShelfWidget::DisableDimmingAnimationsForTest() {
- DCHECK(delegate_view_);
- return delegate_view_->disable_dimming_animations_for_test();
+void ShelfWidget::OnDragEnter() {
+ LOG(ERROR) << "MSW ShelfWidget::OnDragEnter";
+ SetDimsShelf(false);
}
-void ShelfWidget::WillDeleteShelfLayoutManager() {
- shelf_layout_manager_->RemoveObserver(this);
- shelf_layout_manager_ = NULL;
+void ShelfWidget::OnDragExit() {
+ LOG(ERROR) << "MSW ShelfWidget::OnDragExit";
+ SetDimsShelf(true);
}
void ShelfWidget::OnMouseEvent(ui::MouseEvent* event) {
« no previous file with comments | « ash/shelf/shelf_widget.h ('k') | ui/views/widget/drop_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698