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

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

Issue 10834140: aura: Fix launcher tooltips: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: patch Created 8 years, 4 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/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/window_animations.h" 10 #include "ash/wm/window_animations.h"
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/message_loop.h" 12 #include "base/message_loop.h"
13 #include "base/time.h" 13 #include "base/time.h"
14 #include "base/timer.h" 14 #include "base/timer.h"
15 #include "ui/aura/event.h" 15 #include "ui/aura/event.h"
16 #include "ui/aura/root_window.h" 16 #include "ui/aura/root_window.h"
17 #include "ui/aura/window.h" 17 #include "ui/aura/window.h"
18 #include "ui/base/events.h" 18 #include "ui/base/events.h"
19 #include "ui/gfx/insets.h" 19 #include "ui/gfx/insets.h"
20 #include "ui/views/bubble/bubble_delegate.h" 20 #include "ui/views/bubble/bubble_delegate.h"
21 #include "ui/views/bubble/bubble_frame_view.h"
22 #include "ui/views/bubble/bubble_border_geometric.h"
21 #include "ui/views/controls/label.h" 23 #include "ui/views/controls/label.h"
22 #include "ui/views/layout/fill_layout.h" 24 #include "ui/views/layout/fill_layout.h"
23 #include "ui/views/widget/widget.h" 25 #include "ui/views/widget/widget.h"
24 26
25 namespace ash { 27 namespace ash {
26 namespace internal { 28 namespace internal {
27 namespace { 29 namespace {
28 const int kTooltipMargin = 3; 30 const int kTooltipTopBottomMargin = 3;
31 const int kTooltipLeftRightMargin = 10;
29 const int kTooltipAppearanceDelay = 200; // msec 32 const int kTooltipAppearanceDelay = 200; // msec
33 const int kTooltipMinHeight = 29 - 2 * kTooltipTopBottomMargin;
34 const SkColor kTooltipTextColor = SkColorSetRGB(127, 127, 127);
30 35
31 // The maximum width of the tooltip bubble. Borrowed the value from 36 // The maximum width of the tooltip bubble. Borrowed the value from
32 // ash/tooltip/tooltip_controller.cc 37 // ash/tooltip/tooltip_controller.cc
33 const int kTooltipMaxWidth = 400; 38 const int kTooltipMaxWidth = 250;
39
40 // Bubble border metrics
41 const int kArrowHeight = 7;
42 const int kArrowWidth = 15;
43 const int kShadowWidth = 8;
44 // The distance between the arrow tip and edge of the anchor view.
45 const int kArrowOffset = -10;
34 46
35 views::BubbleBorder::ArrowLocation GetArrowLocation(ShelfAlignment alignment) { 47 views::BubbleBorder::ArrowLocation GetArrowLocation(ShelfAlignment alignment) {
36 switch (alignment) { 48 switch (alignment) {
37 case SHELF_ALIGNMENT_LEFT: 49 case SHELF_ALIGNMENT_LEFT:
38 return views::BubbleBorder::LEFT_BOTTOM; 50 return views::BubbleBorder::LEFT_BOTTOM;
39 case SHELF_ALIGNMENT_RIGHT: 51 case SHELF_ALIGNMENT_RIGHT:
40 return views::BubbleBorder::RIGHT_BOTTOM; 52 return views::BubbleBorder::RIGHT_BOTTOM;
41 case SHELF_ALIGNMENT_BOTTOM: 53 case SHELF_ALIGNMENT_BOTTOM:
42 return views::BubbleBorder::BOTTOM_RIGHT; 54 return views::BubbleBorder::BOTTOM_RIGHT;
43 } 55 }
44 56
45 return views::BubbleBorder::NONE; 57 return views::BubbleBorder::NONE;
46 } 58 }
47 } // namespace 59 } // namespace
48 60
49 // The implementation of tooltip of the launcher. 61 // The implementation of tooltip of the launcher.
50 class LauncherTooltipManager::LauncherTooltipBubble 62 class LauncherTooltipManager::LauncherTooltipBubble
51 : public views::BubbleDelegateView { 63 : public views::BubbleDelegateView {
52 public: 64 public:
53 LauncherTooltipBubble(views::View* anchor, 65 LauncherTooltipBubble(views::View* anchor,
54 views::BubbleBorder::ArrowLocation arrow_location, 66 views::BubbleBorder::ArrowLocation arrow_location,
55 LauncherTooltipManager* host); 67 LauncherTooltipManager* host);
56 68
57 void SetText(const string16& text); 69 void SetText(const string16& text);
58 void Close(); 70 void Close();
59 71
60 private: 72 private:
73 // Overridden from views::BubbleDelegateView:
74 virtual gfx::Rect GetBubbleBounds() OVERRIDE;
75
61 // views::WidgetDelegate overrides: 76 // views::WidgetDelegate overrides:
62 virtual void WindowClosing() OVERRIDE; 77 virtual void WindowClosing() OVERRIDE;
63 78
79 // views::View overrides:
80 virtual gfx::Size GetPreferredSize() OVERRIDE;
81
64 LauncherTooltipManager* host_; 82 LauncherTooltipManager* host_;
65 views::Label* label_; 83 views::Label* label_;
84 views::BubbleBorderGeometric* bubble_border_;
66 }; 85 };
sky 2012/08/03 17:59:25 DISALLOW...
varunjain 2012/08/03 18:22:42 Done.
67 86
68 LauncherTooltipManager::LauncherTooltipBubble::LauncherTooltipBubble( 87 LauncherTooltipManager::LauncherTooltipBubble::LauncherTooltipBubble(
69 views::View* anchor, 88 views::View* anchor,
70 views::BubbleBorder::ArrowLocation arrow_location, 89 views::BubbleBorder::ArrowLocation arrow_location,
71 LauncherTooltipManager* host) 90 LauncherTooltipManager* host)
72 : views::BubbleDelegateView(anchor, arrow_location), 91 : views::BubbleDelegateView(anchor, arrow_location),
73 host_(host) { 92 host_(host),
93 bubble_border_(NULL) {
74 set_close_on_esc(false); 94 set_close_on_esc(false);
75 set_close_on_deactivate(false); 95 set_close_on_deactivate(false);
76 set_use_focusless(true); 96 set_use_focusless(true);
77 set_margins(gfx::Insets(kTooltipMargin, kTooltipMargin, kTooltipMargin, 97 set_margins(gfx::Insets(kTooltipTopBottomMargin, kTooltipLeftRightMargin,
78 kTooltipMargin)); 98 kTooltipTopBottomMargin, kTooltipLeftRightMargin));
79 SetLayoutManager(new views::FillLayout()); 99 SetLayoutManager(new views::FillLayout());
80 // The anchor may not have the widget in tests. 100 // The anchor may not have the widget in tests.
81 if (anchor->GetWidget() && anchor->GetWidget()->GetNativeView()) { 101 if (anchor->GetWidget() && anchor->GetWidget()->GetNativeView()) {
82 aura::RootWindow* root_window = 102 aura::RootWindow* root_window =
83 anchor->GetWidget()->GetNativeView()->GetRootWindow(); 103 anchor->GetWidget()->GetNativeView()->GetRootWindow();
84 set_parent_window(ash::Shell::GetInstance()->GetContainer( 104 set_parent_window(ash::Shell::GetInstance()->GetContainer(
85 root_window, ash::internal::kShellWindowId_SettingBubbleContainer)); 105 root_window, ash::internal::kShellWindowId_SettingBubbleContainer));
86 } 106 }
87 label_ = new views::Label; 107 label_ = new views::Label;
88 label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); 108 label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
109 label_->SetEnabledColor(kTooltipTextColor);
89 AddChildView(label_); 110 AddChildView(label_);
111 views::BubbleDelegateView::CreateBubble(this);
112 bubble_border_ = new views::BubbleBorderGeometric(
113 views::BubbleBorder::BOTTOM_RIGHT);
114 bubble_border_->SetShadow(gfx::ShadowValue(
115 gfx::Point(0, 5), kShadowWidth, SkColorSetARGB(0x72, 0, 0, 0)));
116 bubble_border_->set_arrow_width(kArrowWidth);
117 bubble_border_->set_arrow_height(kArrowHeight);
118 bubble_border_->set_anchor_edge_offset(kArrowOffset);
119 GetBubbleFrameView()->SetBubbleBorder(bubble_border_);
90 } 120 }
91 121
92 void LauncherTooltipManager::LauncherTooltipBubble::SetText( 122 void LauncherTooltipManager::LauncherTooltipBubble::SetText(
93 const string16& text) { 123 const string16& text) {
94 label_->SetText(text); 124 label_->SetText(text);
95 label_->SetMultiLine(true);
96 label_->SizeToFit(kTooltipMaxWidth);
97 SizeToContents(); 125 SizeToContents();
98 } 126 }
99 127
100 void LauncherTooltipManager::LauncherTooltipBubble::Close() { 128 void LauncherTooltipManager::LauncherTooltipBubble::Close() {
101 if (GetWidget()) { 129 if (GetWidget()) {
102 host_ = NULL; 130 host_ = NULL;
103 GetWidget()->Close(); 131 GetWidget()->Close();
104 } 132 }
105 } 133 }
106 134
135 gfx::Rect LauncherTooltipManager::LauncherTooltipBubble::GetBubbleBounds() {
136 // This happens before replacing the default border.
137 if (!bubble_border_)
138 return views::BubbleDelegateView::GetBubbleBounds();
139
140 const gfx::Rect anchor_rect = GetAnchorRect();
141 gfx::Rect bubble_rect = GetBubbleFrameView()->GetUpdatedWindowBounds(
142 anchor_rect,
143 GetPreferredSize(),
144 false /* try_mirroring_arrow */);
145
146 const gfx::Point old_offset = bubble_border_->offset();
147 bubble_rect = bubble_border_->ComputeOffsetAndUpdateBubbleRect(bubble_rect,
148 anchor_rect);
149
150 // Repaints border if arrow offset is changed.
151 if (bubble_border_->offset() != old_offset)
152 GetBubbleFrameView()->SchedulePaint();
153
154 return bubble_rect;
155 }
156
107 void LauncherTooltipManager::LauncherTooltipBubble::WindowClosing() { 157 void LauncherTooltipManager::LauncherTooltipBubble::WindowClosing() {
108 views::BubbleDelegateView::WindowClosing(); 158 views::BubbleDelegateView::WindowClosing();
109 if (host_) 159 if (host_)
110 host_->OnBubbleClosed(this); 160 host_->OnBubbleClosed(this);
111 } 161 }
112 162
163 gfx::Size LauncherTooltipManager::LauncherTooltipBubble::GetPreferredSize() {
164 gfx::Size pref_size = views::BubbleDelegateView::GetPreferredSize();
165 if (pref_size.height() < kTooltipMinHeight)
166 pref_size.set_height(kTooltipMinHeight);
167 if (pref_size.width() > kTooltipMaxWidth)
168 pref_size.set_width(kTooltipMaxWidth);
169 return pref_size;
170 }
171
113 LauncherTooltipManager::LauncherTooltipManager( 172 LauncherTooltipManager::LauncherTooltipManager(
114 ShelfAlignment alignment, 173 ShelfAlignment alignment,
115 ShelfLayoutManager* shelf_layout_manager, 174 ShelfLayoutManager* shelf_layout_manager,
116 LauncherView* launcher_view) 175 LauncherView* launcher_view)
117 : view_(NULL), 176 : view_(NULL),
118 widget_(NULL), 177 widget_(NULL),
119 anchor_(NULL), 178 anchor_(NULL),
120 alignment_(alignment), 179 alignment_(alignment),
121 shelf_layout_manager_(shelf_layout_manager), 180 shelf_layout_manager_(shelf_layout_manager),
122 launcher_view_(launcher_view) { 181 launcher_view_(launcher_view) {
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 } 391 }
333 392
334 void LauncherTooltipManager::CreateBubble(views::View* anchor, 393 void LauncherTooltipManager::CreateBubble(views::View* anchor,
335 const string16& text) { 394 const string16& text) {
336 DCHECK(!view_); 395 DCHECK(!view_);
337 396
338 anchor_ = anchor; 397 anchor_ = anchor;
339 text_ = text; 398 text_ = text;
340 view_ = new LauncherTooltipBubble( 399 view_ = new LauncherTooltipBubble(
341 anchor, GetArrowLocation(alignment_), this); 400 anchor, GetArrowLocation(alignment_), this);
342 views::BubbleDelegateView::CreateBubble(view_);
343 widget_ = view_->GetWidget(); 401 widget_ = view_->GetWidget();
344 view_->SetText(text_); 402 view_->SetText(text_);
345 403
346 gfx::NativeView native_view = widget_->GetNativeView(); 404 gfx::NativeView native_view = widget_->GetNativeView();
347 SetWindowVisibilityAnimationType( 405 SetWindowVisibilityAnimationType(
348 native_view, WINDOW_VISIBILITY_ANIMATION_TYPE_VERTICAL); 406 native_view, WINDOW_VISIBILITY_ANIMATION_TYPE_VERTICAL);
349 SetWindowVisibilityAnimationTransition(native_view, ANIMATE_HIDE); 407 SetWindowVisibilityAnimationTransition(native_view, ANIMATE_HIDE);
350 } 408 }
351 409
352 } // namespace internal 410 } // namespace internal
353 } // namespace ash 411 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | ui/app_list/app_list_bubble_border.h » ('j') | ui/views/bubble/bubble_border_geometric.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698