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

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

Issue 11434099: Use the correct launcher assets for shelf alignment. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years 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/launcher/launcher_view.h" 7 #include "ash/launcher/launcher_view.h"
8 #include "ash/shell.h" 8 #include "ash/shell.h"
9 #include "ash/shell_window_ids.h" 9 #include "ash/shell_window_ids.h"
10 #include "ash/wm/session_state_controller.h" 10 #include "ash/wm/session_state_controller.h"
11 #include "ash/wm/session_state_observer.h" 11 #include "ash/wm/session_state_observer.h"
12 #include "ash/wm/shelf_layout_manager.h"
12 #include "ash/wm/window_animations.h" 13 #include "ash/wm/window_animations.h"
13 #include "base/bind.h" 14 #include "base/bind.h"
14 #include "base/message_loop.h" 15 #include "base/message_loop.h"
15 #include "base/time.h" 16 #include "base/time.h"
16 #include "base/timer.h" 17 #include "base/timer.h"
17 #include "ui/aura/root_window.h" 18 #include "ui/aura/root_window.h"
18 #include "ui/aura/window.h" 19 #include "ui/aura/window.h"
19 #include "ui/base/events/event.h" 20 #include "ui/base/events/event.h"
20 #include "ui/base/events/event_constants.h" 21 #include "ui/base/events/event_constants.h"
21 #include "ui/gfx/insets.h" 22 #include "ui/gfx/insets.h"
(...skipping 12 matching lines...) Expand all
34 const int kTooltipMinHeight = 29 - 2 * kTooltipTopBottomMargin; 35 const int kTooltipMinHeight = 29 - 2 * kTooltipTopBottomMargin;
35 const SkColor kTooltipTextColor = SkColorSetRGB(0x22, 0x22, 0x22); 36 const SkColor kTooltipTextColor = SkColorSetRGB(0x22, 0x22, 0x22);
36 37
37 // The maximum width of the tooltip bubble. Borrowed the value from 38 // The maximum width of the tooltip bubble. Borrowed the value from
38 // ash/tooltip/tooltip_controller.cc 39 // ash/tooltip/tooltip_controller.cc
39 const int kTooltipMaxWidth = 250; 40 const int kTooltipMaxWidth = 250;
40 41
41 // The distance between the arrow tip and edge of the anchor view. 42 // The distance between the arrow tip and edge of the anchor view.
42 const int kArrowOffset = 10; 43 const int kArrowOffset = 10;
43 44
44 views::BubbleBorder::ArrowLocation GetArrowLocation(ShelfAlignment alignment) {
45 switch (alignment) {
46 case SHELF_ALIGNMENT_LEFT:
47 return views::BubbleBorder::LEFT_CENTER;
48 case SHELF_ALIGNMENT_RIGHT:
49 return views::BubbleBorder::RIGHT_CENTER;
50 case SHELF_ALIGNMENT_BOTTOM:
51 return views::BubbleBorder::BOTTOM_CENTER;
52 }
53
54 return views::BubbleBorder::NONE;
55 }
56 } // namespace 45 } // namespace
57 46
58 // The implementation of tooltip of the launcher. 47 // The implementation of tooltip of the launcher.
59 class LauncherTooltipManager::LauncherTooltipBubble 48 class LauncherTooltipManager::LauncherTooltipBubble
60 : public views::BubbleDelegateView { 49 : public views::BubbleDelegateView {
61 public: 50 public:
62 LauncherTooltipBubble(views::View* anchor, 51 LauncherTooltipBubble(views::View* anchor,
63 views::BubbleBorder::ArrowLocation arrow_location, 52 views::BubbleBorder::ArrowLocation arrow_location,
64 LauncherTooltipManager* host); 53 LauncherTooltipManager* host);
65 54
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 gfx::Size LauncherTooltipManager::LauncherTooltipBubble::GetPreferredSize() { 121 gfx::Size LauncherTooltipManager::LauncherTooltipBubble::GetPreferredSize() {
133 gfx::Size pref_size = views::BubbleDelegateView::GetPreferredSize(); 122 gfx::Size pref_size = views::BubbleDelegateView::GetPreferredSize();
134 if (pref_size.height() < kTooltipMinHeight) 123 if (pref_size.height() < kTooltipMinHeight)
135 pref_size.set_height(kTooltipMinHeight); 124 pref_size.set_height(kTooltipMinHeight);
136 if (pref_size.width() > kTooltipMaxWidth) 125 if (pref_size.width() > kTooltipMaxWidth)
137 pref_size.set_width(kTooltipMaxWidth); 126 pref_size.set_width(kTooltipMaxWidth);
138 return pref_size; 127 return pref_size;
139 } 128 }
140 129
141 LauncherTooltipManager::LauncherTooltipManager( 130 LauncherTooltipManager::LauncherTooltipManager(
142 ShelfAlignment alignment,
143 ShelfLayoutManager* shelf_layout_manager, 131 ShelfLayoutManager* shelf_layout_manager,
144 LauncherView* launcher_view) 132 LauncherView* launcher_view)
145 : view_(NULL), 133 : view_(NULL),
146 widget_(NULL), 134 widget_(NULL),
147 anchor_(NULL), 135 anchor_(NULL),
148 alignment_(alignment),
149 shelf_layout_manager_(shelf_layout_manager), 136 shelf_layout_manager_(shelf_layout_manager),
150 launcher_view_(launcher_view) { 137 launcher_view_(launcher_view) {
151 if (shelf_layout_manager) 138 if (shelf_layout_manager)
152 shelf_layout_manager->AddObserver(this); 139 shelf_layout_manager->AddObserver(this);
153 if (Shell::HasInstance()) { 140 if (Shell::HasInstance()) {
154 Shell::GetInstance()->AddPreTargetHandler(this); 141 Shell::GetInstance()->AddPreTargetHandler(this);
155 Shell::GetInstance()->session_state_controller()->AddObserver(this); 142 Shell::GetInstance()->session_state_controller()->AddObserver(this);
156 } 143 }
157 } 144 }
158 145
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 } 197 }
211 } 198 }
212 199
213 void LauncherTooltipManager::OnBubbleClosed(views::BubbleDelegateView* view) { 200 void LauncherTooltipManager::OnBubbleClosed(views::BubbleDelegateView* view) {
214 if (view == view_) { 201 if (view == view_) {
215 view_ = NULL; 202 view_ = NULL;
216 widget_ = NULL; 203 widget_ = NULL;
217 } 204 }
218 } 205 }
219 206
220 void LauncherTooltipManager::SetArrowLocation(ShelfAlignment alignment) { 207 void LauncherTooltipManager::UpdateArrowLocation() {
221 if (alignment_ == alignment)
222 return;
223
224 alignment_ = alignment;
225 if (view_) { 208 if (view_) {
226 CancelHidingAnimation(); 209 CancelHidingAnimation();
227 Close(); 210 Close();
228 ShowImmediately(anchor_, text_); 211 ShowImmediately(anchor_, text_);
229 } 212 }
230 } 213 }
231 214
232 void LauncherTooltipManager::ResetTimer() { 215 void LauncherTooltipManager::ResetTimer() {
233 if (timer_.get() && timer_->IsRunning()) { 216 if (timer_.get() && timer_->IsRunning()) {
234 timer_->Reset(); 217 timer_->Reset();
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 344
362 timer_.reset(); 345 timer_.reset();
363 } 346 }
364 347
365 void LauncherTooltipManager::CreateBubble(views::View* anchor, 348 void LauncherTooltipManager::CreateBubble(views::View* anchor,
366 const string16& text) { 349 const string16& text) {
367 DCHECK(!view_); 350 DCHECK(!view_);
368 351
369 anchor_ = anchor; 352 anchor_ = anchor;
370 text_ = text; 353 text_ = text;
371 view_ = new LauncherTooltipBubble( 354 views::BubbleBorder::ArrowLocation arrow_location =
372 anchor, GetArrowLocation(alignment_), this); 355 shelf_layout_manager_->SelectValueForShelfAlignment(
356 views::BubbleBorder::BOTTOM_CENTER,
357 views::BubbleBorder::LEFT_CENTER,
358 views::BubbleBorder::RIGHT_CENTER);
359
360 view_ = new LauncherTooltipBubble(anchor, arrow_location, this);
373 widget_ = view_->GetWidget(); 361 widget_ = view_->GetWidget();
374 view_->SetText(text_); 362 view_->SetText(text_);
375 363
376 gfx::NativeView native_view = widget_->GetNativeView(); 364 gfx::NativeView native_view = widget_->GetNativeView();
377 views::corewm::SetWindowVisibilityAnimationType( 365 views::corewm::SetWindowVisibilityAnimationType(
378 native_view, views::corewm::WINDOW_VISIBILITY_ANIMATION_TYPE_VERTICAL); 366 native_view, views::corewm::WINDOW_VISIBILITY_ANIMATION_TYPE_VERTICAL);
379 views::corewm::SetWindowVisibilityAnimationTransition( 367 views::corewm::SetWindowVisibilityAnimationTransition(
380 native_view, views::corewm::ANIMATE_HIDE); 368 native_view, views::corewm::ANIMATE_HIDE);
381 } 369 }
382 370
383 } // namespace internal 371 } // namespace internal
384 } // namespace ash 372 } // 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