| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "ash/common/shelf/shelf_tooltip_manager.h" | 5 #include "ash/common/shelf/shelf_tooltip_manager.h" |
| 6 | 6 |
| 7 #include "ash/common/shelf/shelf_view.h" | 7 #include "ash/common/shelf/shelf_view.h" |
| 8 #include "ash/common/shelf/wm_shelf.h" | 8 #include "ash/common/shelf/wm_shelf.h" |
| 9 #include "ash/common/system/tray/tray_constants.h" | 9 #include "ash/common/system/tray/tray_constants.h" |
| 10 #include "ash/common/wm_lookup.h" | |
| 11 #include "ash/common/wm_shell.h" | 10 #include "ash/common/wm_shell.h" |
| 12 #include "ash/common/wm_window.h" | 11 #include "ash/common/wm_window.h" |
| 13 #include "ash/public/cpp/shell_window_ids.h" | 12 #include "ash/public/cpp/shell_window_ids.h" |
| 14 #include "ash/root_window_controller.h" | 13 #include "ash/root_window_controller.h" |
| 15 #include "base/bind.h" | 14 #include "base/bind.h" |
| 16 #include "base/strings/string16.h" | 15 #include "base/strings/string16.h" |
| 17 #include "base/threading/thread_task_runner_handle.h" | 16 #include "base/threading/thread_task_runner_handle.h" |
| 18 #include "base/time/time.h" | 17 #include "base/time/time.h" |
| 19 #include "ui/base/material_design/material_design_controller.h" | 18 #include "ui/base/material_design/material_design_controller.h" |
| 20 #include "ui/events/event.h" | 19 #include "ui/events/event.h" |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 gfx::Size GetPreferredSize() const override { | 101 gfx::Size GetPreferredSize() const override { |
| 103 const gfx::Size size = BubbleDialogDelegateView::GetPreferredSize(); | 102 const gfx::Size size = BubbleDialogDelegateView::GetPreferredSize(); |
| 104 const int kTooltipMinHeight = kTooltipHeight - 2 * kTooltipTopBottomMargin; | 103 const int kTooltipMinHeight = kTooltipHeight - 2 * kTooltipTopBottomMargin; |
| 105 return gfx::Size(std::min(size.width(), kTooltipMaxWidth), | 104 return gfx::Size(std::min(size.width(), kTooltipMaxWidth), |
| 106 std::max(size.height(), kTooltipMinHeight)); | 105 std::max(size.height(), kTooltipMinHeight)); |
| 107 } | 106 } |
| 108 | 107 |
| 109 void OnBeforeBubbleWidgetInit(views::Widget::InitParams* params, | 108 void OnBeforeBubbleWidgetInit(views::Widget::InitParams* params, |
| 110 views::Widget* bubble_widget) const override { | 109 views::Widget* bubble_widget) const override { |
| 111 // Place the bubble in the same display as the anchor. | 110 // Place the bubble in the same display as the anchor. |
| 112 WmLookup::Get() | 111 WmWindow::Get(anchor_widget()->GetNativeWindow()) |
| 113 ->GetWindowForWidget(anchor_widget()) | |
| 114 ->GetRootWindowController() | 112 ->GetRootWindowController() |
| 115 ->ConfigureWidgetInitParamsForContainer( | 113 ->ConfigureWidgetInitParamsForContainer( |
| 116 bubble_widget, kShellWindowId_SettingBubbleContainer, params); | 114 bubble_widget, kShellWindowId_SettingBubbleContainer, params); |
| 117 } | 115 } |
| 118 | 116 |
| 119 int GetDialogButtons() const override { return ui::DIALOG_BUTTON_NONE; } | 117 int GetDialogButtons() const override { return ui::DIALOG_BUTTON_NONE; } |
| 120 | 118 |
| 121 DISALLOW_COPY_AND_ASSIGN(ShelfTooltipBubble); | 119 DISALLOW_COPY_AND_ASSIGN(ShelfTooltipBubble); |
| 122 }; | 120 }; |
| 123 | 121 |
| 124 ShelfTooltipManager::ShelfTooltipManager(ShelfView* shelf_view) | 122 ShelfTooltipManager::ShelfTooltipManager(ShelfView* shelf_view) |
| 125 : timer_delay_(kTooltipAppearanceDelay), | 123 : timer_delay_(kTooltipAppearanceDelay), |
| 126 shelf_view_(shelf_view), | 124 shelf_view_(shelf_view), |
| 127 bubble_(nullptr), | 125 bubble_(nullptr), |
| 128 weak_factory_(this) { | 126 weak_factory_(this) { |
| 129 shelf_view_->wm_shelf()->AddObserver(this); | 127 shelf_view_->wm_shelf()->AddObserver(this); |
| 130 WmShell::Get()->AddPointerWatcher(this, | 128 WmShell::Get()->AddPointerWatcher(this, |
| 131 views::PointerWatcherEventTypes::BASIC); | 129 views::PointerWatcherEventTypes::BASIC); |
| 132 } | 130 } |
| 133 | 131 |
| 134 ShelfTooltipManager::~ShelfTooltipManager() { | 132 ShelfTooltipManager::~ShelfTooltipManager() { |
| 135 WmShell::Get()->RemovePointerWatcher(this); | 133 WmShell::Get()->RemovePointerWatcher(this); |
| 136 shelf_view_->wm_shelf()->RemoveObserver(this); | 134 shelf_view_->wm_shelf()->RemoveObserver(this); |
| 137 WmWindow* window = nullptr; | 135 WmWindow* window = nullptr; |
| 138 if (shelf_view_->GetWidget()) | 136 if (shelf_view_->GetWidget()) |
| 139 window = WmLookup::Get()->GetWindowForWidget(shelf_view_->GetWidget()); | 137 window = WmWindow::Get(shelf_view_->GetWidget()->GetNativeWindow()); |
| 140 if (window) | 138 if (window) |
| 141 window->RemoveLimitedPreTargetHandler(this); | 139 window->RemoveLimitedPreTargetHandler(this); |
| 142 } | 140 } |
| 143 | 141 |
| 144 void ShelfTooltipManager::Init() { | 142 void ShelfTooltipManager::Init() { |
| 145 WmWindow* window = | 143 WmWindow* window = WmWindow::Get(shelf_view_->GetWidget()->GetNativeWindow()); |
| 146 WmLookup::Get()->GetWindowForWidget(shelf_view_->GetWidget()); | |
| 147 window->AddLimitedPreTargetHandler(this); | 144 window->AddLimitedPreTargetHandler(this); |
| 148 } | 145 } |
| 149 | 146 |
| 150 void ShelfTooltipManager::Close() { | 147 void ShelfTooltipManager::Close() { |
| 151 timer_.Stop(); | 148 timer_.Stop(); |
| 152 if (bubble_) | 149 if (bubble_) |
| 153 bubble_->GetWidget()->Close(); | 150 bubble_->GetWidget()->Close(); |
| 154 bubble_ = nullptr; | 151 bubble_ = nullptr; |
| 155 } | 152 } |
| 156 | 153 |
| 157 bool ShelfTooltipManager::IsVisible() const { | 154 bool ShelfTooltipManager::IsVisible() const { |
| 158 return bubble_ && bubble_->GetWidget()->IsVisible(); | 155 return bubble_ && bubble_->GetWidget()->IsVisible(); |
| 159 } | 156 } |
| 160 | 157 |
| 161 views::View* ShelfTooltipManager::GetCurrentAnchorView() const { | 158 views::View* ShelfTooltipManager::GetCurrentAnchorView() const { |
| 162 return bubble_ ? bubble_->GetAnchorView() : nullptr; | 159 return bubble_ ? bubble_->GetAnchorView() : nullptr; |
| 163 } | 160 } |
| 164 | 161 |
| 165 void ShelfTooltipManager::ShowTooltip(views::View* view) { | 162 void ShelfTooltipManager::ShowTooltip(views::View* view) { |
| 166 timer_.Stop(); | 163 timer_.Stop(); |
| 167 if (bubble_) { | 164 if (bubble_) { |
| 168 // Cancel the hiding animation to hide the old bubble immediately. | 165 // Cancel the hiding animation to hide the old bubble immediately. |
| 169 WmLookup::Get() | 166 WmWindow::Get(bubble_->GetWidget()->GetNativeWindow()) |
| 170 ->GetWindowForWidget(bubble_->GetWidget()) | |
| 171 ->SetVisibilityAnimationTransition(::wm::ANIMATE_NONE); | 167 ->SetVisibilityAnimationTransition(::wm::ANIMATE_NONE); |
| 172 Close(); | 168 Close(); |
| 173 } | 169 } |
| 174 | 170 |
| 175 if (!ShouldShowTooltipForView(view)) | 171 if (!ShouldShowTooltipForView(view)) |
| 176 return; | 172 return; |
| 177 | 173 |
| 178 views::BubbleBorder::Arrow arrow = views::BubbleBorder::Arrow::NONE; | 174 views::BubbleBorder::Arrow arrow = views::BubbleBorder::Arrow::NONE; |
| 179 switch (shelf_view_->wm_shelf()->GetAlignment()) { | 175 switch (shelf_view_->wm_shelf()->GetAlignment()) { |
| 180 case SHELF_ALIGNMENT_BOTTOM: | 176 case SHELF_ALIGNMENT_BOTTOM: |
| 181 case SHELF_ALIGNMENT_BOTTOM_LOCKED: | 177 case SHELF_ALIGNMENT_BOTTOM_LOCKED: |
| 182 arrow = views::BubbleBorder::BOTTOM_CENTER; | 178 arrow = views::BubbleBorder::BOTTOM_CENTER; |
| 183 break; | 179 break; |
| 184 case SHELF_ALIGNMENT_LEFT: | 180 case SHELF_ALIGNMENT_LEFT: |
| 185 arrow = views::BubbleBorder::LEFT_CENTER; | 181 arrow = views::BubbleBorder::LEFT_CENTER; |
| 186 break; | 182 break; |
| 187 case SHELF_ALIGNMENT_RIGHT: | 183 case SHELF_ALIGNMENT_RIGHT: |
| 188 arrow = views::BubbleBorder::RIGHT_CENTER; | 184 arrow = views::BubbleBorder::RIGHT_CENTER; |
| 189 break; | 185 break; |
| 190 } | 186 } |
| 191 | 187 |
| 192 base::string16 text = shelf_view_->GetTitleForView(view); | 188 base::string16 text = shelf_view_->GetTitleForView(view); |
| 193 bubble_ = new ShelfTooltipBubble(view, arrow, text); | 189 bubble_ = new ShelfTooltipBubble(view, arrow, text); |
| 194 WmWindow* window = WmLookup::Get()->GetWindowForWidget(bubble_->GetWidget()); | 190 WmWindow* window = WmWindow::Get(bubble_->GetWidget()->GetNativeWindow()); |
| 195 window->SetVisibilityAnimationType( | 191 window->SetVisibilityAnimationType( |
| 196 ::wm::WINDOW_VISIBILITY_ANIMATION_TYPE_VERTICAL); | 192 ::wm::WINDOW_VISIBILITY_ANIMATION_TYPE_VERTICAL); |
| 197 window->SetVisibilityAnimationTransition(::wm::ANIMATE_HIDE); | 193 window->SetVisibilityAnimationTransition(::wm::ANIMATE_HIDE); |
| 198 bubble_->GetWidget()->Show(); | 194 bubble_->GetWidget()->Show(); |
| 199 } | 195 } |
| 200 | 196 |
| 201 void ShelfTooltipManager::ShowTooltipWithDelay(views::View* view) { | 197 void ShelfTooltipManager::ShowTooltipWithDelay(views::View* view) { |
| 202 if (ShouldShowTooltipForView(view)) { | 198 if (ShouldShowTooltipForView(view)) { |
| 203 timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(timer_delay_), | 199 timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(timer_delay_), |
| 204 base::Bind(&ShelfTooltipManager::ShowTooltip, | 200 base::Bind(&ShelfTooltipManager::ShowTooltip, |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 | 254 |
| 259 bool ShelfTooltipManager::ShouldShowTooltipForView(views::View* view) { | 255 bool ShelfTooltipManager::ShouldShowTooltipForView(views::View* view) { |
| 260 WmShelf* shelf = shelf_view_ ? shelf_view_->wm_shelf() : nullptr; | 256 WmShelf* shelf = shelf_view_ ? shelf_view_->wm_shelf() : nullptr; |
| 261 return shelf && shelf_view_->ShouldShowTooltipForView(view) && | 257 return shelf && shelf_view_->ShouldShowTooltipForView(view) && |
| 262 (shelf->GetVisibilityState() == SHELF_VISIBLE || | 258 (shelf->GetVisibilityState() == SHELF_VISIBLE || |
| 263 (shelf->GetVisibilityState() == SHELF_AUTO_HIDE && | 259 (shelf->GetVisibilityState() == SHELF_AUTO_HIDE && |
| 264 shelf->GetAutoHideState() == SHELF_AUTO_HIDE_SHOWN)); | 260 shelf->GetAutoHideState() == SHELF_AUTO_HIDE_SHOWN)); |
| 265 } | 261 } |
| 266 | 262 |
| 267 } // namespace ash | 263 } // namespace ash |
| OLD | NEW |