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

Side by Side Diff: ash/launcher/launcher_tooltip_manager.cc

Issue 10701051: Polish launcher tooltip visibility (2nd try). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/launcher/launcher_tooltip_manager.h" 5 #include "ash/launcher/launcher_tooltip_manager.h"
6 6
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "ash/shell_window_ids.h" 8 #include "ash/shell_window_ids.h"
9 #include "ash/wm/window_animations.h" 9 #include "ash/wm/window_animations.h"
10 #include "base/bind.h"
11 #include "base/message_loop.h"
10 #include "base/time.h" 12 #include "base/time.h"
11 #include "base/timer.h" 13 #include "base/timer.h"
12 #include "ui/aura/window.h" 14 #include "ui/aura/window.h"
13 #include "ui/views/bubble/bubble_delegate.h" 15 #include "ui/views/bubble/bubble_delegate.h"
14 #include "ui/views/controls/label.h" 16 #include "ui/views/controls/label.h"
15 #include "ui/views/layout/fill_layout.h" 17 #include "ui/views/layout/fill_layout.h"
16 #include "ui/views/widget/widget.h" 18 #include "ui/views/widget/widget.h"
17 19
18 namespace ash { 20 namespace ash {
19 namespace internal { 21 namespace internal {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 set_close_on_esc(false); 71 set_close_on_esc(false);
70 set_close_on_deactivate(false); 72 set_close_on_deactivate(false);
71 set_use_focusless(true); 73 set_use_focusless(true);
72 set_margin(kTooltipMargin); 74 set_margin(kTooltipMargin);
73 SetLayoutManager(new views::FillLayout()); 75 SetLayoutManager(new views::FillLayout());
74 // The anchor may not have the widget in tests. 76 // The anchor may not have the widget in tests.
75 if (anchor->GetWidget() && anchor->GetWidget()->GetNativeView()) { 77 if (anchor->GetWidget() && anchor->GetWidget()->GetNativeView()) {
76 aura::RootWindow* root_window = 78 aura::RootWindow* root_window =
77 anchor->GetWidget()->GetNativeView()->GetRootWindow(); 79 anchor->GetWidget()->GetNativeView()->GetRootWindow();
78 set_parent_window(ash::Shell::GetInstance()->GetContainer( 80 set_parent_window(ash::Shell::GetInstance()->GetContainer(
79 root_window, ash::internal::kShellWindowId_SettingBubbleContainer)); 81 root_window, ash::internal::kShellWindowId_LauncherContainer));
80 } 82 }
81 label_ = new views::Label; 83 label_ = new views::Label;
82 label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); 84 label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
83 AddChildView(label_); 85 AddChildView(label_);
84 } 86 }
85 87
86 void LauncherTooltipManager::LauncherTooltipBubble::SetText( 88 void LauncherTooltipManager::LauncherTooltipBubble::SetText(
87 const string16& text) { 89 const string16& text) {
88 label_->SetText(text); 90 label_->SetText(text);
89 label_->SetMultiLine(true); 91 label_->SetMultiLine(true);
90 label_->SizeToFit(kTooltipMaxWidth); 92 label_->SizeToFit(kTooltipMaxWidth);
91 SizeToContents(); 93 SizeToContents();
92 } 94 }
93 95
94 void LauncherTooltipManager::LauncherTooltipBubble::OnMouseExited( 96 void LauncherTooltipManager::LauncherTooltipBubble::OnMouseExited(
95 const views::MouseEvent& event) { 97 const views::MouseEvent& event) {
96 GetWidget()->Close(); 98 GetWidget()->Close();
97 host_->OnBubbleClosed(this); 99 host_->OnBubbleClosed(this);
98 } 100 }
99 101
100 void LauncherTooltipManager::LauncherTooltipBubble::WindowClosing() { 102 void LauncherTooltipManager::LauncherTooltipBubble::WindowClosing() {
101 views::BubbleDelegateView::WindowClosing(); 103 views::BubbleDelegateView::WindowClosing();
102 host_->OnBubbleClosed(this); 104 host_->OnBubbleClosed(this);
103 } 105 }
104 106
105 LauncherTooltipManager::LauncherTooltipManager(ShelfAlignment alignment) 107 LauncherTooltipManager::LauncherTooltipManager(
108 ShelfAlignment alignment, ShelfLayoutManager* shelf_layout_manager)
106 : view_(NULL), 109 : view_(NULL),
107 anchor_(NULL), 110 anchor_(NULL),
108 alignment_(alignment) {} 111 alignment_(alignment),
112 shelf_layout_manager_(shelf_layout_manager) {
113 if (shelf_layout_manager)
114 shelf_layout_manager->AddObserver(this);
115 }
109 116
110 LauncherTooltipManager::~LauncherTooltipManager() { 117 LauncherTooltipManager::~LauncherTooltipManager() {
111 Close(); 118 Close();
119 if (shelf_layout_manager_)
120 shelf_layout_manager_->RemoveObserver(this);
112 } 121 }
113 122
114 void LauncherTooltipManager::ShowDelayed(views::View* anchor, 123 void LauncherTooltipManager::ShowDelayed(views::View* anchor,
115 const string16& text) { 124 const string16& text) {
116 if (view_) { 125 if (view_) {
117 if (timer_.get() && timer_->IsRunning()) 126 if (timer_.get() && timer_->IsRunning())
118 return; 127 return;
119 else 128 else
120 Close(); 129 Close();
121 } 130 }
122 131
132 if (shelf_layout_manager_ && !shelf_layout_manager_->IsVisible())
133 return;
134
123 CreateBubble(anchor, text); 135 CreateBubble(anchor, text);
124 gfx::NativeView native_view = view_->GetWidget()->GetNativeView(); 136 gfx::NativeView native_view = view_->GetWidget()->GetNativeView();
125 SetWindowVisibilityAnimationType( 137 SetWindowVisibilityAnimationType(
126 native_view, WINDOW_VISIBILITY_ANIMATION_TYPE_VERTICAL); 138 native_view, WINDOW_VISIBILITY_ANIMATION_TYPE_VERTICAL);
127 SetWindowVisibilityAnimationTransition(native_view, ANIMATE_SHOW); 139 SetWindowVisibilityAnimationTransition(native_view, ANIMATE_SHOW);
128 ResetTimer(); 140 ResetTimer();
129 } 141 }
130 142
131 void LauncherTooltipManager::ShowImmediately(views::View* anchor, 143 void LauncherTooltipManager::ShowImmediately(views::View* anchor,
132 const string16& text) { 144 const string16& text) {
133 if (view_ && IsVisible()) 145 if (view_) {
134 Close(); 146 if (timer_.get() && timer_->IsRunning())
147 StopTimer();
148 Close();
149 }
150
151 if (shelf_layout_manager_ && !shelf_layout_manager_->IsVisible())
152 return;
135 153
136 CreateBubble(anchor, text); 154 CreateBubble(anchor, text);
137 gfx::NativeView native_view = view_->GetWidget()->GetNativeView(); 155 gfx::NativeView native_view = view_->GetWidget()->GetNativeView();
138 SetWindowVisibilityAnimationTransition(native_view, ANIMATE_NONE); 156 SetWindowVisibilityAnimationTransition(native_view, ANIMATE_NONE);
139 ShowInternal(); 157 ShowInternal();
140 } 158 }
141 159
142 void LauncherTooltipManager::Close() { 160 void LauncherTooltipManager::Close() {
143 if (view_) { 161 if (view_) {
144 view_->GetWidget()->Close(); 162 view_->GetWidget()->Close();
(...skipping 17 matching lines...) Expand all
162 ShowImmediately(anchor_, text_); 180 ShowImmediately(anchor_, text_);
163 } 181 }
164 } 182 }
165 183
166 void LauncherTooltipManager::ResetTimer() { 184 void LauncherTooltipManager::ResetTimer() {
167 if (timer_.get() && timer_->IsRunning()) { 185 if (timer_.get() && timer_->IsRunning()) {
168 timer_->Reset(); 186 timer_->Reset();
169 return; 187 return;
170 } 188 }
171 189
190 // We don't start the timer if the shelf isn't visible.
191 if (shelf_layout_manager_ && !shelf_layout_manager_->IsVisible())
192 return;
193
172 base::OneShotTimer<LauncherTooltipManager>* new_timer = 194 base::OneShotTimer<LauncherTooltipManager>* new_timer =
173 new base::OneShotTimer<LauncherTooltipManager>(); 195 new base::OneShotTimer<LauncherTooltipManager>();
174 new_timer->Start( 196 new_timer->Start(
175 FROM_HERE, 197 FROM_HERE,
176 base::TimeDelta::FromMilliseconds(kTooltipAppearanceDelay), 198 base::TimeDelta::FromMilliseconds(kTooltipAppearanceDelay),
177 this, 199 this,
178 &LauncherTooltipManager::ShowInternal); 200 &LauncherTooltipManager::ShowInternal);
179 timer_.reset(new_timer); 201 timer_.reset(new_timer);
180 } 202 }
181 203
182 void LauncherTooltipManager::StopTimer() { 204 void LauncherTooltipManager::StopTimer() {
183 timer_.reset(); 205 timer_.reset();
184 } 206 }
185 207
186 bool LauncherTooltipManager::IsVisible() { 208 bool LauncherTooltipManager::IsVisible() {
187 if (timer_.get() && timer_->IsRunning()) 209 if (timer_.get() && timer_->IsRunning())
188 return false; 210 return false;
189 211
190 return view_ && view_->GetWidget() && view_->GetWidget()->IsVisible(); 212 return view_ && view_->GetWidget() && view_->GetWidget()->IsVisible();
191 } 213 }
192 214
215 void LauncherTooltipManager::WillDeleteShelf() {
216 shelf_layout_manager_ = NULL;
217 }
218
219 void LauncherTooltipManager::WillChangeVisibilityState(
220 ShelfLayoutManager::VisibilityState new_state) {
221 if (new_state == ShelfLayoutManager::HIDDEN) {
222 StopTimer();
223 Close();
224 }
225 }
226
227 void LauncherTooltipManager::OnAutoHideStateChanged(
228 ShelfLayoutManager::AutoHideState new_state) {
229 if (new_state == ShelfLayoutManager::AUTO_HIDE_HIDDEN) {
230 StopTimer();
231 // AutoHide state change happens during an event filter, so immediate close
232 // may cause a crash in the HandleMouseEvent() after the filter. So we just
233 // schedule the Close here.
234 MessageLoopForUI::current()->PostTask(
235 FROM_HERE,
236 base::Bind(&LauncherTooltipManager::Close, base::Unretained(this)));
237 }
238 }
239
193 void LauncherTooltipManager::ShowInternal() { 240 void LauncherTooltipManager::ShowInternal() {
194 if (view_) 241 if (view_)
195 view_->Show(); 242 view_->Show();
196 243
197 timer_.reset(); 244 timer_.reset();
198 } 245 }
199 246
200 void LauncherTooltipManager::CreateBubble(views::View* anchor, 247 void LauncherTooltipManager::CreateBubble(views::View* anchor,
201 const string16& text) { 248 const string16& text) {
202 DCHECK(!view_); 249 DCHECK(!view_);
203 250
204 anchor_ = anchor; 251 anchor_ = anchor;
205 text_ = text; 252 text_ = text;
206 view_ = new LauncherTooltipBubble( 253 view_ = new LauncherTooltipBubble(
207 anchor, GetArrowLocation(alignment_), this); 254 anchor, GetArrowLocation(alignment_), this);
208 views::BubbleDelegateView::CreateBubble(view_); 255 views::BubbleDelegateView::CreateBubble(view_);
209 view_->SetText(text_); 256 view_->SetText(text_);
210 } 257 }
211 258
212 } // namespace internal 259 } // namespace internal
213 } // namespace ash 260 } // namespace ash
OLDNEW
« no previous file with comments | « ash/launcher/launcher_tooltip_manager.h ('k') | ash/launcher/launcher_tooltip_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698