Commit 875ca8c1 authored by Manu Cornet's avatar Manu Cornet Committed by Commit Bot

CrOS Shelf: Minor widget activation simplification

In |ShelfWidget|, override |OnNativeWidgetActivationChanged| instead of
|OnWidgetActivationChanged|. This achieves the same purpose, is more
consistent with what |StatusAreaWidget| does, and avoids the need to
add/remove widget observers.

Note that this doesn't directly fix the linked bug but is a step in the
right direction. No behavior change is expected from this change.

Bug: 956080
Change-Id: Id4002b30197a5d6a97baccaaf1a912db39c45e9b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1643413Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Manu Cornet <manucornet@chromium.org>
Cr-Commit-Position: refs/heads/master@{#666027}
parent dac83250
......@@ -368,8 +368,6 @@ ShelfWidget::ShelfWidget(aura::Window* shelf_container, Shelf* shelf)
shelf_layout_manager_->GetShelfBackgroundType(),
AnimationChangeType::IMMEDIATE);
views::Widget::AddObserver(this);
background_animator_.AddObserver(delegate_view_);
shelf_->AddObserver(this);
......@@ -414,7 +412,6 @@ void ShelfWidget::Shutdown() {
// Don't need to observe focus/activation during shutdown.
Shell::Get()->focus_cycler()->RemoveWidget(this);
SetFocusCycler(nullptr);
RemoveObserver(this);
}
void ShelfWidget::CreateStatusAreaWidget(aura::Window* status_container) {
......@@ -522,20 +519,22 @@ void ShelfWidget::FocusFirstOrLastFocusableChild(bool last) {
to_focus->GetFocusManager()->SetFocusedView(to_focus);
}
void ShelfWidget::OnWidgetActivationChanged(views::Widget* widget,
bool active) {
bool ShelfWidget::OnNativeWidgetActivationChanged(bool active) {
if (!Widget::OnNativeWidgetActivationChanged(active))
return false;
if (active) {
// Do not focus the default element if the widget activation came from the
// another widget's focus cycling. The setter of
// |activated_from_other_widget_| should handle focusing the correct view.
if (activated_from_other_widget_) {
activated_from_other_widget_ = false;
return;
return true;
}
delegate_view_->SetPaneFocusAndFocusDefault();
} else {
delegate_view_->GetFocusManager()->ClearFocus();
}
return true;
}
void ShelfWidget::WillDeleteShelfLayoutManager() {
......
......@@ -16,7 +16,6 @@
#include "ash/shelf/shelf_observer.h"
#include "base/macros.h"
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_observer.h"
namespace app_list {
class ApplicationDragAndDropHost;
......@@ -37,7 +36,6 @@ class StatusAreaWidget;
// the status area widget. There is one ShelfWidget per display. It is created
// early during RootWindowController initialization.
class ASH_EXPORT ShelfWidget : public views::Widget,
public views::WidgetObserver,
public ShelfLayoutManagerObserver,
public ShelfObserver,
public SessionObserver,
......@@ -106,10 +104,12 @@ class ASH_EXPORT ShelfWidget : public views::Widget,
// and focuses it.
void FocusFirstOrLastFocusableChild(bool last);
// Overridden from views::WidgetObserver:
void OnWidgetActivationChanged(views::Widget* widget, bool active) override;
// views::Widget:
void OnMouseEvent(ui::MouseEvent* event) override;
void OnGestureEvent(ui::GestureEvent* event) override;
bool OnNativeWidgetActivationChanged(bool active) override;
// ShelfLayoutManagerObserver overrides:
// ShelfLayoutManagerObserver:
void WillDeleteShelfLayoutManager() override;
// ShelfObserver:
......@@ -148,10 +148,6 @@ class ASH_EXPORT ShelfWidget : public views::Widget,
// Shows shelf widget if IsVisible() returns false.
void ShowIfHidden();
// views::Widget:
void OnMouseEvent(ui::MouseEvent* event) override;
void OnGestureEvent(ui::GestureEvent* event) override;
Shelf* shelf_;
ShelfBackgroundAnimator background_animator_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment