| 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/shelf/shelf_tooltip_manager.h" | 5 #include "ash/shelf/shelf_tooltip_manager.h" |
| 6 | 6 |
| 7 #include "ash/common/shell_window_ids.h" | 7 #include "ash/common/shell_window_ids.h" |
| 8 #include "ash/shelf/shelf.h" | 8 #include "ash/shelf/shelf.h" |
| 9 #include "ash/shelf/shelf_layout_manager.h" | 9 #include "ash/shelf/shelf_layout_manager.h" |
| 10 #include "ash/shelf/shelf_view.h" | 10 #include "ash/shelf/shelf_view.h" |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 : timer_delay_(kTooltipAppearanceDelay), | 96 : timer_delay_(kTooltipAppearanceDelay), |
| 97 shelf_view_(shelf_view), | 97 shelf_view_(shelf_view), |
| 98 root_window_(nullptr), | 98 root_window_(nullptr), |
| 99 shelf_layout_manager_(nullptr), | 99 shelf_layout_manager_(nullptr), |
| 100 bubble_(nullptr), | 100 bubble_(nullptr), |
| 101 weak_factory_(this) {} | 101 weak_factory_(this) {} |
| 102 | 102 |
| 103 ShelfTooltipManager::~ShelfTooltipManager() { | 103 ShelfTooltipManager::~ShelfTooltipManager() { |
| 104 WillDeleteShelfLayoutManager(); | 104 WillDeleteShelfLayoutManager(); |
| 105 | 105 |
| 106 Shell::GetInstance()->RemovePointerWatcher(this); | 106 Shell::GetInstance()->RemovePointerDownWatcher(this); |
| 107 | 107 |
| 108 if (root_window_) { | 108 if (root_window_) { |
| 109 root_window_->RemoveObserver(this); | 109 root_window_->RemoveObserver(this); |
| 110 root_window_->RemovePreTargetHandler(this); | 110 root_window_->RemovePreTargetHandler(this); |
| 111 root_window_ = nullptr; | 111 root_window_ = nullptr; |
| 112 } | 112 } |
| 113 } | 113 } |
| 114 | 114 |
| 115 void ShelfTooltipManager::Init() { | 115 void ShelfTooltipManager::Init() { |
| 116 shelf_layout_manager_ = shelf_view_->shelf()->shelf_layout_manager(); | 116 shelf_layout_manager_ = shelf_view_->shelf()->shelf_layout_manager(); |
| 117 shelf_layout_manager_->AddObserver(this); | 117 shelf_layout_manager_->AddObserver(this); |
| 118 | 118 |
| 119 root_window_ = shelf_view_->GetWidget()->GetNativeWindow()->GetRootWindow(); | 119 root_window_ = shelf_view_->GetWidget()->GetNativeWindow()->GetRootWindow(); |
| 120 root_window_->AddPreTargetHandler(this); | 120 root_window_->AddPreTargetHandler(this); |
| 121 root_window_->AddObserver(this); | 121 root_window_->AddObserver(this); |
| 122 | 122 |
| 123 Shell::GetInstance()->AddPointerWatcher(this); | 123 Shell::GetInstance()->AddPointerDownWatcher(this); |
| 124 } | 124 } |
| 125 | 125 |
| 126 void ShelfTooltipManager::Close() { | 126 void ShelfTooltipManager::Close() { |
| 127 timer_.Stop(); | 127 timer_.Stop(); |
| 128 if (bubble_) | 128 if (bubble_) |
| 129 bubble_->GetWidget()->Close(); | 129 bubble_->GetWidget()->Close(); |
| 130 bubble_ = nullptr; | 130 bubble_ = nullptr; |
| 131 } | 131 } |
| 132 | 132 |
| 133 bool ShelfTooltipManager::IsVisible() const { | 133 bool ShelfTooltipManager::IsVisible() const { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 } | 181 } |
| 182 | 182 |
| 183 void ShelfTooltipManager::OnTouchPressed(const ui::TouchEvent& event, | 183 void ShelfTooltipManager::OnTouchPressed(const ui::TouchEvent& event, |
| 184 const gfx::Point& location_in_screen, | 184 const gfx::Point& location_in_screen, |
| 185 views::Widget* target) { | 185 views::Widget* target) { |
| 186 // Close on any touch press events inside or outside the tooltip. | 186 // Close on any touch press events inside or outside the tooltip. |
| 187 Close(); | 187 Close(); |
| 188 } | 188 } |
| 189 | 189 |
| 190 void ShelfTooltipManager::OnEvent(ui::Event* event) { | 190 void ShelfTooltipManager::OnEvent(ui::Event* event) { |
| 191 // Mouse and touch press events are handled via views::PointerWatcher. | 191 // Mouse and touch press events are handled via views::PointerDownWatcher. |
| 192 if (event->type() == ui::ET_MOUSE_PRESSED || | 192 if (event->type() == ui::ET_MOUSE_PRESSED || |
| 193 event->type() == ui::ET_TOUCH_PRESSED) { | 193 event->type() == ui::ET_TOUCH_PRESSED) { |
| 194 return; | 194 return; |
| 195 } | 195 } |
| 196 | 196 |
| 197 if (event->type() == ui::ET_MOUSE_EXITED || !event->IsMouseEvent() || | 197 if (event->type() == ui::ET_MOUSE_EXITED || !event->IsMouseEvent() || |
| 198 event->target() != shelf_view_->GetWidget()->GetNativeWindow()) { | 198 event->target() != shelf_view_->GetWidget()->GetNativeWindow()) { |
| 199 if (!event->IsKeyEvent()) | 199 if (!event->IsKeyEvent()) |
| 200 Close(); | 200 Close(); |
| 201 return; | 201 return; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 base::Bind(&ShelfTooltipManager::Close, weak_factory_.GetWeakPtr())); | 250 base::Bind(&ShelfTooltipManager::Close, weak_factory_.GetWeakPtr())); |
| 251 } | 251 } |
| 252 } | 252 } |
| 253 | 253 |
| 254 bool ShelfTooltipManager::ShouldShowTooltipForView(views::View* view) { | 254 bool ShelfTooltipManager::ShouldShowTooltipForView(views::View* view) { |
| 255 return shelf_view_ && shelf_view_->ShouldShowTooltipForView(view) && | 255 return shelf_view_ && shelf_view_->ShouldShowTooltipForView(view) && |
| 256 shelf_layout_manager_ && shelf_layout_manager_->IsVisible(); | 256 shelf_layout_manager_ && shelf_layout_manager_->IsVisible(); |
| 257 } | 257 } |
| 258 | 258 |
| 259 } // namespace ash | 259 } // namespace ash |
| OLD | NEW |