Commit bbdc142f authored by Andrew Xu's avatar Andrew Xu Committed by Commit Bot

Refactor ShelfTooltipManager

This CL moves ShelfTooltipManager from ShelfView to Shelf.

Bug: 997807
Change-Id: I407d17fabdcbb84957074c88014caa0e3214de7e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1776938
Commit-Queue: Andrew Xu <andrewxu@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarManu Cornet <manucornet@chromium.org>
Cr-Commit-Position: refs/heads/master@{#695893}
parent 74292531
...@@ -611,6 +611,7 @@ component("ash") { ...@@ -611,6 +611,7 @@ component("ash") {
"shelf/shelf_observer.h", "shelf/shelf_observer.h",
"shelf/shelf_tooltip_bubble.cc", "shelf/shelf_tooltip_bubble.cc",
"shelf/shelf_tooltip_bubble.h", "shelf/shelf_tooltip_bubble.h",
"shelf/shelf_tooltip_delegate.h",
"shelf/shelf_tooltip_manager.cc", "shelf/shelf_tooltip_manager.cc",
"shelf/shelf_tooltip_manager.h", "shelf/shelf_tooltip_manager.h",
"shelf/shelf_tooltip_preview_bubble.cc", "shelf/shelf_tooltip_preview_bubble.cc",
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "ash/public/cpp/shelf_config.h" #include "ash/public/cpp/shelf_config.h"
#include "ash/screen_util.h" #include "ash/screen_util.h"
#include "ash/shelf/shelf_focus_cycler.h" #include "ash/shelf/shelf_focus_cycler.h"
#include "ash/shelf/shelf_tooltip_manager.h"
#include "ash/shelf/shelf_widget.h" #include "ash/shelf/shelf_widget.h"
#include "ash/system/status_area_widget.h" #include "ash/system/status_area_widget.h"
#include "ash/wm/tablet_mode/tablet_mode_controller.h" #include "ash/wm/tablet_mode/tablet_mode_controller.h"
...@@ -222,6 +223,7 @@ ScrollableShelfView::ScrollableShelfView(ShelfModel* model, Shelf* shelf) ...@@ -222,6 +223,7 @@ ScrollableShelfView::ScrollableShelfView(ShelfModel* model, Shelf* shelf)
ScrollableShelfView::~ScrollableShelfView() { ScrollableShelfView::~ScrollableShelfView() {
Shell::Get()->RemoveShellObserver(this); Shell::Get()->RemoveShellObserver(this);
GetShelf()->tooltip()->set_shelf_tooltip_delegate(nullptr);
} }
void ScrollableShelfView::Init() { void ScrollableShelfView::Init() {
...@@ -253,6 +255,8 @@ void ScrollableShelfView::Init() { ...@@ -253,6 +255,8 @@ void ScrollableShelfView::Init() {
layer()->SetMaskLayer(gradient_layer_delegate_->layer()); layer()->SetMaskLayer(gradient_layer_delegate_->layer());
focus_search_ = std::make_unique<ScrollableShelfFocusSearch>(this); focus_search_ = std::make_unique<ScrollableShelfFocusSearch>(this);
GetShelf()->tooltip()->set_shelf_tooltip_delegate(shelf_view_);
} }
void ScrollableShelfView::OnFocusRingActivationChanged(bool activated) { void ScrollableShelfView::OnFocusRingActivationChanged(bool activated) {
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "ash/shelf/shelf_focus_cycler.h" #include "ash/shelf/shelf_focus_cycler.h"
#include "ash/shelf/shelf_layout_manager.h" #include "ash/shelf/shelf_layout_manager.h"
#include "ash/shelf/shelf_observer.h" #include "ash/shelf/shelf_observer.h"
#include "ash/shelf/shelf_tooltip_manager.h"
#include "ash/shelf/shelf_widget.h" #include "ash/shelf/shelf_widget.h"
#include "ash/shell.h" #include "ash/shell.h"
#include "ash/system/status_area_widget.h" #include "ash/system/status_area_widget.h"
...@@ -82,7 +83,8 @@ class Shelf::AutoHideEventHandler : public ui::EventHandler { ...@@ -82,7 +83,8 @@ class Shelf::AutoHideEventHandler : public ui::EventHandler {
Shelf::Shelf() Shelf::Shelf()
: shelf_locking_manager_(this), : shelf_locking_manager_(this),
shelf_focus_cycler_(std::make_unique<ShelfFocusCycler>(this)) {} shelf_focus_cycler_(std::make_unique<ShelfFocusCycler>(this)),
tooltip_(std::make_unique<ShelfTooltipManager>(this)) {}
Shelf::~Shelf() = default; Shelf::~Shelf() = default;
...@@ -187,6 +189,7 @@ void Shelf::SetAlignment(ShelfAlignment alignment) { ...@@ -187,6 +189,7 @@ void Shelf::SetAlignment(ShelfAlignment alignment) {
alignment_ = alignment; alignment_ = alignment;
// The ShelfWidget notifies the ShelfView of the alignment change. // The ShelfWidget notifies the ShelfView of the alignment change.
shelf_widget_->OnShelfAlignmentChanged(); shelf_widget_->OnShelfAlignmentChanged();
tooltip_->Close();
shelf_layout_manager_->LayoutShelf(); shelf_layout_manager_->LayoutShelf();
Shell::Get()->NotifyShelfAlignmentChanged(GetWindow()->GetRootWindow()); Shell::Get()->NotifyShelfAlignmentChanged(GetWindow()->GetRootWindow());
} }
......
...@@ -40,6 +40,7 @@ class StatusAreaWidget; ...@@ -40,6 +40,7 @@ class StatusAreaWidget;
class ShelfObserver; class ShelfObserver;
class TrayBackgroundView; class TrayBackgroundView;
class WorkAreaInsets; class WorkAreaInsets;
class ShelfTooltipManager;
// Controller for the shelf state. One per display, because each display might // Controller for the shelf state. One per display, because each display might
// have different shelf alignment, autohide, etc. Exists for the lifetime of the // have different shelf alignment, autohide, etc. Exists for the lifetime of the
...@@ -182,6 +183,8 @@ class ASH_EXPORT Shelf : public ShelfLayoutManagerObserver { ...@@ -182,6 +183,8 @@ class ASH_EXPORT Shelf : public ShelfLayoutManagerObserver {
} }
int auto_hide_lock() const { return auto_hide_lock_; } int auto_hide_lock() const { return auto_hide_lock_; }
ShelfTooltipManager* tooltip() { return tooltip_.get(); }
protected: protected:
// ShelfLayoutManagerObserver: // ShelfLayoutManagerObserver:
void WillDeleteShelfLayoutManager() override; void WillDeleteShelfLayoutManager() override;
...@@ -233,6 +236,8 @@ class ASH_EXPORT Shelf : public ShelfLayoutManagerObserver { ...@@ -233,6 +236,8 @@ class ASH_EXPORT Shelf : public ShelfLayoutManagerObserver {
// shelf. // shelf.
int auto_hide_lock_ = 0; int auto_hide_lock_ = 0;
std::unique_ptr<ShelfTooltipManager> tooltip_;
DISALLOW_COPY_AND_ASSIGN(Shelf); DISALLOW_COPY_AND_ASSIGN(Shelf);
}; };
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_SHELF_SHELF_TOOLTIP_DELEGATE_H_
#define ASH_SHELF_SHELF_TOOLTIP_DELEGATE_H_
#include <vector>
#include "ash/ash_export.h"
#include "base/strings/string16.h"
namespace gfx {
class Point;
}
namespace ui {
class Event;
}
namespace views {
class View;
}
namespace aura {
class Window;
}
namespace ash {
// Interface provided to ShelfTooltipManager to create the tooltip for children.
class ASH_EXPORT ShelfTooltipDelegate {
public:
ShelfTooltipDelegate() = default;
virtual ~ShelfTooltipDelegate() = default;
// Returns true if a tooltip should be shown for |view|.
virtual bool ShouldShowTooltipForView(const views::View* view) const = 0;
// Returns true if the mouse cursor exits the area for launcher tooltip.
virtual bool ShouldHideTooltip(const gfx::Point& cursor_point) const = 0;
// Returns the list of open windows that correspond to the app represented by
// this shelf view.
virtual const std::vector<aura::Window*> GetOpenWindowsForView(
views::View* view) = 0;
// Returns the title of |view|.
virtual base::string16 GetTitleForView(const views::View* view) const = 0;
// Returns the view that should handle |event|.
virtual views::View* GetViewForEvent(const ui::Event& event) = 0;
};
} // namespace ash
#endif // ASH_SHELF_SHELF_TOOLTIP_DELEGATE_H_
\ No newline at end of file
...@@ -6,8 +6,8 @@ ...@@ -6,8 +6,8 @@
#include "ash/shelf/shelf.h" #include "ash/shelf/shelf.h"
#include "ash/shelf/shelf_tooltip_bubble.h" #include "ash/shelf/shelf_tooltip_bubble.h"
#include "ash/shelf/shelf_tooltip_delegate.h"
#include "ash/shelf/shelf_tooltip_preview_bubble.h" #include "ash/shelf/shelf_tooltip_preview_bubble.h"
#include "ash/shelf/shelf_view.h"
#include "ash/shelf/shelf_widget.h" #include "ash/shelf/shelf_widget.h"
#include "ash/shell.h" #include "ash/shell.h"
#include "base/bind.h" #include "base/bind.h"
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
#include "ui/events/event.h" #include "ui/events/event.h"
#include "ui/events/event_constants.h" #include "ui/events/event_constants.h"
#include "ui/gfx/geometry/insets.h" #include "ui/gfx/geometry/insets.h"
#include "ui/views/widget/widget.h"
#include "ui/wm/core/window_animations.h" #include "ui/wm/core/window_animations.h"
namespace ash { namespace ash {
...@@ -29,17 +28,15 @@ const int kTooltipAppearanceDelay = 250; // msec ...@@ -29,17 +28,15 @@ const int kTooltipAppearanceDelay = 250; // msec
} // namespace } // namespace
ShelfTooltipManager::ShelfTooltipManager(ShelfView* shelf_view) ShelfTooltipManager::ShelfTooltipManager(Shelf* shelf)
: timer_delay_(kTooltipAppearanceDelay), shelf_view_(shelf_view) { : timer_delay_(kTooltipAppearanceDelay), shelf_(shelf) {
shelf_view_->shelf()->AddObserver(this); shelf_->AddObserver(this);
Shell::Get()->AddPreTargetHandler(this); Shell::Get()->AddPreTargetHandler(this);
} }
ShelfTooltipManager::~ShelfTooltipManager() { ShelfTooltipManager::~ShelfTooltipManager() {
Shell::Get()->RemovePreTargetHandler(this); Shell::Get()->RemovePreTargetHandler(this);
shelf_view_->shelf()->RemoveObserver(this); shelf_->RemoveObserver(this);
if (shelf_view_->GetWidget() && shelf_view_->GetWidget()->GetNativeWindow())
shelf_view_->GetWidget()->GetNativeWindow()->RemovePreTargetHandler(this);
} }
void ShelfTooltipManager::Close(bool animate) { void ShelfTooltipManager::Close(bool animate) {
...@@ -72,18 +69,19 @@ void ShelfTooltipManager::ShowTooltip(views::View* view) { ...@@ -72,18 +69,19 @@ void ShelfTooltipManager::ShowTooltip(views::View* view) {
return; return;
const std::vector<aura::Window*> open_windows = const std::vector<aura::Window*> open_windows =
shelf_view_->GetOpenWindowsForShelfView(view); shelf_tooltip_delegate_->GetOpenWindowsForView(view);
const ShelfAlignment alignment = shelf_view_->shelf()->alignment(); const ShelfAlignment alignment = shelf_->alignment();
const SkColor shelf_background_color = const SkColor shelf_background_color =
shelf_view_->shelf_widget()->GetShelfBackgroundColor(); shelf_->shelf_widget()->GetShelfBackgroundColor();
if (chromeos::switches::ShouldShowShelfHoverPreviews() && if (chromeos::switches::ShouldShowShelfHoverPreviews() &&
open_windows.size() > 0) { open_windows.size() > 0) {
bubble_ = new ShelfTooltipPreviewBubble(view, open_windows, this, alignment, bubble_ = new ShelfTooltipPreviewBubble(view, open_windows, this, alignment,
shelf_background_color); shelf_background_color);
} else { } else {
bubble_ = new ShelfTooltipBubble(view, alignment, shelf_background_color, bubble_ =
shelf_view_->GetTitleForView(view)); new ShelfTooltipBubble(view, alignment, shelf_background_color,
shelf_tooltip_delegate_->GetTitleForView(view));
} }
aura::Window* window = bubble_->GetWidget()->GetNativeWindow(); aura::Window* window = bubble_->GetWidget()->GetNativeWindow();
...@@ -115,17 +113,23 @@ void ShelfTooltipManager::OnMouseEvent(ui::MouseEvent* event) { ...@@ -115,17 +113,23 @@ void ShelfTooltipManager::OnMouseEvent(ui::MouseEvent* event) {
return; return;
} }
// Happens in tests where mouse events are picked up before
// |shelf_tooltip_delegate_| is set.
if (!shelf_tooltip_delegate_)
return;
views::View* delegate_view = shelf_tooltip_delegate_->GetViewForEvent(*event);
// The code below handles mouse move events within the shelf window. // The code below handles mouse move events within the shelf window.
if (event->type() != ui::ET_MOUSE_MOVED || if (event->type() != ui::ET_MOUSE_MOVED || !delegate_view) {
event->target() != shelf_view_->GetWidget()->GetNativeWindow()) {
// Don't show delayed tooltips if the mouse is being active elsewhere. // Don't show delayed tooltips if the mouse is being active elsewhere.
timer_.Stop(); timer_.Stop();
return; return;
} }
gfx::Point point = event->location(); gfx::Point point = event->location();
views::View::ConvertPointFromWidget(shelf_view_, &point); views::View::ConvertPointFromWidget(delegate_view, &point);
views::View* view = shelf_view_->GetTooltipHandlerForPoint(point); views::View* view = delegate_view->GetTooltipHandlerForPoint(point);
const bool should_show = ShouldShowTooltipForView(view); const bool should_show = ShouldShowTooltipForView(view);
timer_.Stop(); timer_.Stop();
...@@ -133,7 +137,7 @@ void ShelfTooltipManager::OnMouseEvent(ui::MouseEvent* event) { ...@@ -133,7 +137,7 @@ void ShelfTooltipManager::OnMouseEvent(ui::MouseEvent* event) {
ShowTooltip(view); ShowTooltip(view);
else if (!IsVisible() && should_show) else if (!IsVisible() && should_show)
ShowTooltipWithDelay(view); ShowTooltipWithDelay(view);
else if (IsVisible() && shelf_view_->ShouldHideTooltip(point)) else if (IsVisible() && shelf_tooltip_delegate_->ShouldHideTooltip(point))
Close(); Close();
} }
...@@ -159,12 +163,14 @@ void ShelfTooltipManager::OnAutoHideStateChanged(ShelfAutoHideState new_state) { ...@@ -159,12 +163,14 @@ void ShelfTooltipManager::OnAutoHideStateChanged(ShelfAutoHideState new_state) {
} }
bool ShelfTooltipManager::ShouldShowTooltipForView(views::View* view) { bool ShelfTooltipManager::ShouldShowTooltipForView(views::View* view) {
Shelf* shelf = shelf_view_ ? shelf_view_->shelf() : nullptr; const bool shelf_visibility =
return shelf && shelf_view_->GetVisible() && shelf_ && (shelf_->GetVisibilityState() == SHELF_VISIBLE ||
shelf_view_->ShouldShowTooltipForView(view) && (shelf_->GetVisibilityState() == SHELF_AUTO_HIDE &&
(shelf->GetVisibilityState() == SHELF_VISIBLE || shelf_->GetAutoHideState() == SHELF_AUTO_HIDE_SHOWN));
(shelf->GetVisibilityState() == SHELF_AUTO_HIDE &&
shelf->GetAutoHideState() == SHELF_AUTO_HIDE_SHOWN)); if (!shelf_visibility)
return false;
return shelf_tooltip_delegate_->ShouldShowTooltipForView(view);
} }
void ShelfTooltipManager::ProcessPressedEvent(const ui::LocatedEvent& event) { void ShelfTooltipManager::ProcessPressedEvent(const ui::LocatedEvent& event) {
......
...@@ -22,13 +22,14 @@ class View; ...@@ -22,13 +22,14 @@ class View;
namespace ash { namespace ash {
class ShelfBubble; class ShelfBubble;
class ShelfView; class Shelf;
class ShelfTooltipDelegate;
// ShelfTooltipManager manages the tooltip bubble that appears for shelf items. // ShelfTooltipManager manages the tooltip bubble that appears for shelf items.
class ASH_EXPORT ShelfTooltipManager : public ui::EventHandler, class ASH_EXPORT ShelfTooltipManager : public ui::EventHandler,
public ShelfObserver { public ShelfObserver {
public: public:
explicit ShelfTooltipManager(ShelfView* shelf_view); explicit ShelfTooltipManager(Shelf* shelf);
~ShelfTooltipManager() override; ~ShelfTooltipManager() override;
// Closes the tooltip; uses an animation if |animate| is true. // Closes the tooltip; uses an animation if |animate| is true.
...@@ -47,6 +48,13 @@ class ASH_EXPORT ShelfTooltipManager : public ui::EventHandler, ...@@ -47,6 +48,13 @@ class ASH_EXPORT ShelfTooltipManager : public ui::EventHandler,
// Set the timer delay in ms for testing. // Set the timer delay in ms for testing.
void set_timer_delay_for_test(int timer_delay) { timer_delay_ = timer_delay; } void set_timer_delay_for_test(int timer_delay) { timer_delay_ = timer_delay; }
void set_shelf_tooltip_delegate(
ShelfTooltipDelegate* shelf_tooltip_delegate) {
DCHECK(!shelf_tooltip_delegate_ || !shelf_tooltip_delegate);
shelf_tooltip_delegate_ = shelf_tooltip_delegate;
}
protected: protected:
// ui::EventHandler overrides: // ui::EventHandler overrides:
void OnMouseEvent(ui::MouseEvent* event) override; void OnMouseEvent(ui::MouseEvent* event) override;
...@@ -69,9 +77,11 @@ class ASH_EXPORT ShelfTooltipManager : public ui::EventHandler, ...@@ -69,9 +77,11 @@ class ASH_EXPORT ShelfTooltipManager : public ui::EventHandler,
int timer_delay_; int timer_delay_;
base::OneShotTimer timer_; base::OneShotTimer timer_;
ShelfView* shelf_view_; Shelf* shelf_ = nullptr;
ShelfBubble* bubble_ = nullptr; ShelfBubble* bubble_ = nullptr;
ShelfTooltipDelegate* shelf_tooltip_delegate_ = nullptr;
base::WeakPtrFactory<ShelfTooltipManager> weak_factory_{this}; base::WeakPtrFactory<ShelfTooltipManager> weak_factory_{this};
DISALLOW_COPY_AND_ASSIGN(ShelfTooltipManager); DISALLOW_COPY_AND_ASSIGN(ShelfTooltipManager);
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include "ash/shelf/shelf_controller.h" #include "ash/shelf/shelf_controller.h"
#include "ash/shelf/shelf_focus_cycler.h" #include "ash/shelf/shelf_focus_cycler.h"
#include "ash/shelf/shelf_menu_model_adapter.h" #include "ash/shelf/shelf_menu_model_adapter.h"
#include "ash/shelf/shelf_tooltip_manager.h"
#include "ash/shelf/shelf_widget.h" #include "ash/shelf/shelf_widget.h"
#include "ash/shell.h" #include "ash/shell.h"
#include "ash/shell_delegate.h" #include "ash/shell_delegate.h"
...@@ -302,7 +303,6 @@ ShelfView::ShelfView(ShelfModel* model, Shelf* shelf) ...@@ -302,7 +303,6 @@ ShelfView::ShelfView(ShelfModel* model, Shelf* shelf)
shelf_(shelf), shelf_(shelf),
view_model_(std::make_unique<views::ViewModel>()), view_model_(std::make_unique<views::ViewModel>()),
bounds_animator_(std::make_unique<views::BoundsAnimator>(this)), bounds_animator_(std::make_unique<views::BoundsAnimator>(this)),
tooltip_(this),
focus_search_(std::make_unique<ShelfFocusSearch>(this)) { focus_search_(std::make_unique<ShelfFocusSearch>(this)) {
DCHECK(model_); DCHECK(model_);
DCHECK(shelf_); DCHECK(shelf_);
...@@ -325,6 +325,10 @@ ShelfView::~ShelfView() { ...@@ -325,6 +325,10 @@ ShelfView::~ShelfView() {
Shell::Get()->RemoveShellObserver(this); Shell::Get()->RemoveShellObserver(this);
bounds_animator_->RemoveObserver(this); bounds_animator_->RemoveObserver(this);
model_->RemoveObserver(this); model_->RemoveObserver(this);
// Resets the shelf tooltip delegate when the main shelf gets destroyed.
if (!is_overflow_mode())
shelf_->tooltip()->set_shelf_tooltip_delegate(nullptr);
} }
int ShelfView::GetSizeOfAppIcons(int count, bool with_overflow) { int ShelfView::GetSizeOfAppIcons(int count, bool with_overflow) {
...@@ -369,6 +373,10 @@ void ShelfView::Init() { ...@@ -369,6 +373,10 @@ void ShelfView::Init() {
AddChildView(overflow_button_); AddChildView(overflow_button_);
// We'll layout when our bounds change. // We'll layout when our bounds change.
// Add the main shelf view as ShelfTooltipDelegate.
if (!is_overflow_mode())
shelf_->tooltip()->set_shelf_tooltip_delegate(this);
} }
gfx::Rect ShelfView::GetIdealBoundsOfItemIcon(const ShelfID& id) { gfx::Rect ShelfView::GetIdealBoundsOfItemIcon(const ShelfID& id) {
...@@ -410,7 +418,7 @@ void ShelfView::UpdateVisibleShelfItemBoundsUnion() { ...@@ -410,7 +418,7 @@ void ShelfView::UpdateVisibleShelfItemBoundsUnion() {
for (int i = std::max(0, first_visible_index_); i <= last_visible_index_; for (int i = std::max(0, first_visible_index_); i <= last_visible_index_;
++i) { ++i) {
const views::View* child = view_model_->view_at(i); const views::View* child = view_model_->view_at(i);
if (ShouldShowTooltipForView(child)) if (ShouldShowTooltipForChildView(child))
visible_shelf_item_bounds_union_.Union(child->GetMirroredBounds()); visible_shelf_item_bounds_union_.Union(child->GetMirroredBounds());
} }
// Also include the overflow button if it is visible. // Also include the overflow button if it is visible.
...@@ -420,26 +428,73 @@ void ShelfView::UpdateVisibleShelfItemBoundsUnion() { ...@@ -420,26 +428,73 @@ void ShelfView::UpdateVisibleShelfItemBoundsUnion() {
} }
} }
bool ShelfView::ShouldShowTooltipForView(const views::View* view) const {
if (!view || !view->parent())
return false;
if (view->parent() == this)
return ShouldShowTooltipForChildView(view);
if (view->parent() != overflow_shelf())
return false;
return overflow_shelf() &&
overflow_shelf()->ShouldShowTooltipForChildView(view);
}
bool ShelfView::ShouldHideTooltip(const gfx::Point& cursor_location) const { bool ShelfView::ShouldHideTooltip(const gfx::Point& cursor_location) const {
// There are thin gaps between launcher buttons but the tooltip shouldn't hide
// in the gaps, but the tooltip should hide if the mouse moved totally outside
// of the buttons area.
return !visible_shelf_item_bounds_union_.Contains(cursor_location); return !visible_shelf_item_bounds_union_.Contains(cursor_location);
} }
bool ShelfView::ShouldShowTooltipForView(const views::View* view) const { const std::vector<aura::Window*> ShelfView::GetOpenWindowsForView(
if (view == overflow_button_) views::View* view) {
return true; std::vector<aura::Window*> window_list =
// Don't show a tooltip for a view that's currently being dragged. Shell::Get()->mru_window_tracker()->BuildWindowForCycleList(kActiveDesk);
if (view == drag_view_) std::vector<aura::Window*> open_windows;
return false; const ShelfItem* item = ShelfItemForView(view);
return ShelfItemForView(view) && !IsShowingMenuForView(view); // The concept of a list of open windows doesn't make sense for something
// that isn't an app shortcut: return an empty list.
if (!item)
return open_windows;
for (auto* window : window_list) {
const std::string window_app_id =
ShelfID::Deserialize(window->GetProperty(kShelfIDKey)).app_id;
if (window_app_id == item->id.app_id) {
// TODO: In the very first version we only show one window. Add the proper
// UI to show all windows for a given open app.
open_windows.push_back(window);
}
}
return open_windows;
} }
base::string16 ShelfView::GetTitleForView(const views::View* view) const { base::string16 ShelfView::GetTitleForView(const views::View* view) const {
if (view == overflow_button_) if (view->parent() == this)
return overflow_button_->GetAccessibleName(); return GetTitleForChildView(view);
const ShelfItem* item = ShelfItemForView(view); if (view->parent() == overflow_shelf())
return item ? item->title : base::string16(); return overflow_shelf()->GetTitleForChildView(view);
return base::string16();
}
views::View* ShelfView::GetViewForEvent(const ui::Event& event) {
if (event.target() == GetWidget()->GetNativeWindow())
return this;
ShelfView* overflow_shelf_view = overflow_shelf();
if (overflow_shelf_view &&
(event.target() == overflow_shelf_view->GetWidget()->GetNativeWindow())) {
return overflow_shelf_view;
}
return nullptr;
} }
void ShelfView::ToggleOverflowBubble() { void ShelfView::ToggleOverflowBubble() {
...@@ -608,7 +663,7 @@ View* ShelfView::GetTooltipHandlerForPoint(const gfx::Point& point) { ...@@ -608,7 +663,7 @@ View* ShelfView::GetTooltipHandlerForPoint(const gfx::Point& point) {
gfx::Point point_in_child_coords(point); gfx::Point point_in_child_coords(point);
ConvertPointToTarget(this, child, &point_in_child_coords); ConvertPointToTarget(this, child, &point_in_child_coords);
if (child->HitTestPoint(point_in_child_coords) && if (child->HitTestPoint(point_in_child_coords) &&
ShouldShowTooltipForView(child)) { ShouldShowTooltipForChildView(child)) {
return child; return child;
} }
} }
...@@ -855,30 +910,6 @@ bool ShelfView::IsDraggedView(const views::View* view) const { ...@@ -855,30 +910,6 @@ bool ShelfView::IsDraggedView(const views::View* view) const {
return drag_view_ == view; return drag_view_ == view;
} }
const std::vector<aura::Window*> ShelfView::GetOpenWindowsForShelfView(
views::View* view) {
std::vector<aura::Window*> window_list =
Shell::Get()->mru_window_tracker()->BuildWindowForCycleList(kActiveDesk);
std::vector<aura::Window*> open_windows;
const ShelfItem* item = ShelfItemForView(view);
// The concept of a list of open windows doesn't make sense for something
// that isn't an app shortcut: return an empty list.
if (!item)
return open_windows;
for (auto* window : window_list) {
const std::string window_app_id =
ShelfID::Deserialize(window->GetProperty(kShelfIDKey)).app_id;
if (window_app_id == item->id.app_id) {
// TODO: In the very first version we only show one window. Add the proper
// UI to show all windows for a given open app.
open_windows.push_back(window);
}
}
return open_windows;
}
views::View* ShelfView::FindFirstFocusableChild() { views::View* ShelfView::FindFirstFocusableChild() {
if (view_model_->view_size() == 0) if (view_model_->view_size() == 0)
return nullptr; return nullptr;
...@@ -2082,8 +2113,8 @@ void ShelfView::ShelfItemRemoved(int model_index, const ShelfItem& old_item) { ...@@ -2082,8 +2113,8 @@ void ShelfView::ShelfItemRemoved(int model_index, const ShelfItem& old_item) {
AnimateToIdealBounds(); AnimateToIdealBounds();
} }
if (view == tooltip_.GetCurrentAnchorView()) if (view == shelf_->tooltip()->GetCurrentAnchorView())
tooltip_.Close(); shelf_->tooltip()->Close();
} }
void ShelfView::ShelfItemChanged(int model_index, const ShelfItem& old_item) { void ShelfView::ShelfItemChanged(int model_index, const ShelfItem& old_item) {
...@@ -2179,7 +2210,6 @@ void ShelfView::OnShelfAlignmentChanged(aura::Window* root_window) { ...@@ -2179,7 +2210,6 @@ void ShelfView::OnShelfAlignmentChanged(aura::Window* root_window) {
if (i >= first_visible_index_ && i <= last_visible_index_) if (i >= first_visible_index_ && i <= last_visible_index_)
view_model_->view_at(i)->Layout(); view_model_->view_at(i)->Layout();
} }
tooltip_.Close();
if (overflow_bubble_) if (overflow_bubble_)
overflow_bubble_->Hide(); overflow_bubble_->Hide();
...@@ -2418,4 +2448,23 @@ bool ShelfView::ShouldHandleGestures(const ui::GestureEvent& event) const { ...@@ -2418,4 +2448,23 @@ bool ShelfView::ShouldHandleGestures(const ui::GestureEvent& event) const {
return true; return true;
} }
base::string16 ShelfView::GetTitleForChildView(const views::View* view) const {
if (view == overflow_button_)
return overflow_button_->GetAccessibleName();
const ShelfItem* item = ShelfItemForView(view);
return item ? item->title : base::string16();
}
bool ShelfView::ShouldShowTooltipForChildView(
const views::View* child_view) const {
if (child_view == overflow_button_)
return true;
// Don't show a tooltip for a view that's currently being dragged.
if (child_view == drag_view_)
return false;
return ShelfItemForView(child_view) && !IsShowingMenuForView(child_view);
}
} // namespace ash } // namespace ash
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
#include "ash/shelf/shelf.h" #include "ash/shelf/shelf.h"
#include "ash/shelf/shelf_button_delegate.h" #include "ash/shelf/shelf_button_delegate.h"
#include "ash/shelf/shelf_button_pressed_metric_tracker.h" #include "ash/shelf/shelf_button_pressed_metric_tracker.h"
#include "ash/shelf/shelf_tooltip_manager.h" #include "ash/shelf/shelf_tooltip_delegate.h"
#include "ash/shell_observer.h" #include "ash/shell_observer.h"
#include "ash/system/model/virtual_keyboard_model.h" #include "ash/system/model/virtual_keyboard_model.h"
#include "base/macros.h" #include "base/macros.h"
...@@ -112,6 +112,7 @@ class ASH_EXPORT ShelfView : public views::AccessiblePaneView, ...@@ -112,6 +112,7 @@ class ASH_EXPORT ShelfView : public views::AccessiblePaneView,
public views::ContextMenuController, public views::ContextMenuController,
public views::BoundsAnimatorObserver, public views::BoundsAnimatorObserver,
public app_list::ApplicationDragAndDropHost, public app_list::ApplicationDragAndDropHost,
public ShelfTooltipDelegate,
public ash::TabletModeObserver, public ash::TabletModeObserver,
public VirtualKeyboardModel::Observer { public VirtualKeyboardModel::Observer {
public: public:
...@@ -158,17 +159,13 @@ class ASH_EXPORT ShelfView : public views::AccessiblePaneView, ...@@ -158,17 +159,13 @@ class ASH_EXPORT ShelfView : public views::AccessiblePaneView,
// for showing tooltips without stuttering over gaps. // for showing tooltips without stuttering over gaps.
void UpdateVisibleShelfItemBoundsUnion(); void UpdateVisibleShelfItemBoundsUnion();
// Returns true if the mouse cursor exits the area for launcher tooltip. // ShelfTooltipDelegate:
// There are thin gaps between launcher buttons but the tooltip shouldn't hide bool ShouldShowTooltipForView(const views::View* view) const override;
// in the gaps, but the tooltip should hide if the mouse moved totally outside bool ShouldHideTooltip(const gfx::Point& cursor_location) const override;
// of the buttons area. const std::vector<aura::Window*> GetOpenWindowsForView(
bool ShouldHideTooltip(const gfx::Point& cursor_location) const; views::View* view) override;
base::string16 GetTitleForView(const views::View* view) const override;
// Returns true if a tooltip should be shown for the shelf item |view|. views::View* GetViewForEvent(const ui::Event& event) override;
bool ShouldShowTooltipForView(const views::View* view) const;
// Returns the title of the shelf item |view|.
base::string16 GetTitleForView(const views::View* view) const;
// Toggles the overflow menu. // Toggles the overflow menu.
void ToggleOverflowBubble(); void ToggleOverflowBubble();
...@@ -266,11 +263,6 @@ class ASH_EXPORT ShelfView : public views::AccessiblePaneView, ...@@ -266,11 +263,6 @@ class ASH_EXPORT ShelfView : public views::AccessiblePaneView,
// True if the current |drag_view_| is the given |drag_view|. // True if the current |drag_view_| is the given |drag_view|.
bool IsDraggedView(const views::View* drag_view) const; bool IsDraggedView(const views::View* drag_view) const;
// Returns the list of open windows that correspond to the app represented by
// this shelf view.
const std::vector<aura::Window*> GetOpenWindowsForShelfView(
views::View* view);
// The three methods below return the first or last focusable child of the // The three methods below return the first or last focusable child of the
// set including both the main shelf and the overflow shelf it it's showing. // set including both the main shelf and the overflow shelf it it's showing.
// - The first focusable child is either the home button, or the back // - The first focusable child is either the home button, or the back
...@@ -298,6 +290,11 @@ class ASH_EXPORT ShelfView : public views::AccessiblePaneView, ...@@ -298,6 +290,11 @@ class ASH_EXPORT ShelfView : public views::AccessiblePaneView,
// Returns the overflow shelf. This can be called on either the main shelf // Returns the overflow shelf. This can be called on either the main shelf
// or the overflow shelf. Returns nullptr if the overflow shelf isn't visible. // or the overflow shelf. Returns nullptr if the overflow shelf isn't visible.
ShelfView* overflow_shelf() { ShelfView* overflow_shelf() {
return const_cast<ShelfView*>(
const_cast<const ShelfView*>(this)->overflow_shelf());
}
const ShelfView* overflow_shelf() const {
if (is_overflow_mode()) if (is_overflow_mode())
return this; return this;
return IsShowingOverflowBubble() return IsShowingOverflowBubble()
...@@ -549,6 +546,12 @@ class ASH_EXPORT ShelfView : public views::AccessiblePaneView, ...@@ -549,6 +546,12 @@ class ASH_EXPORT ShelfView : public views::AccessiblePaneView,
bool ShouldHandleGestures(const ui::GestureEvent& event) const; bool ShouldHandleGestures(const ui::GestureEvent& event) const;
// Different from GetTitleForView, |view| here must be a child view.
base::string16 GetTitleForChildView(const views::View* view) const;
// Different from ShouldShowTooltipForView, |view| here must be a child view.
bool ShouldShowTooltipForChildView(const views::View* child_view) const;
// The model; owned by Launcher. // The model; owned by Launcher.
ShelfModel* model_; ShelfModel* model_;
...@@ -578,8 +581,6 @@ class ASH_EXPORT ShelfView : public views::AccessiblePaneView, ...@@ -578,8 +581,6 @@ class ASH_EXPORT ShelfView : public views::AccessiblePaneView,
OverflowBubble* owner_overflow_bubble_ = nullptr; OverflowBubble* owner_overflow_bubble_ = nullptr;
ShelfTooltipManager tooltip_;
// Pointer device that initiated the current drag operation. If there is no // Pointer device that initiated the current drag operation. If there is no
// current dragging operation, this is NONE. // current dragging operation, this is NONE.
Pointer drag_pointer_ = NONE; Pointer drag_pointer_ = NONE;
......
...@@ -130,7 +130,7 @@ OverflowBubble* ShelfViewTestAPI::overflow_bubble() { ...@@ -130,7 +130,7 @@ OverflowBubble* ShelfViewTestAPI::overflow_bubble() {
} }
ShelfTooltipManager* ShelfViewTestAPI::tooltip_manager() { ShelfTooltipManager* ShelfViewTestAPI::tooltip_manager() {
return &shelf_view_->tooltip_; return shelf_view_->shelf()->tooltip();
} }
int ShelfViewTestAPI::GetMinimumDragDistance() const { int ShelfViewTestAPI::GetMinimumDragDistance() const {
......
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