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

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

Issue 10905311: Consolidate bubble border code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove USE_AURA ifdef for kBigShadowImages and kSmalleShadowImages Created 8 years, 3 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
« no previous file with comments | « no previous file | ash/launcher/overflow_bubble.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/root_window.h" 15 #include "ui/aura/root_window.h"
16 #include "ui/aura/window.h" 16 #include "ui/aura/window.h"
17 #include "ui/base/events/event.h" 17 #include "ui/base/events/event.h"
18 #include "ui/base/events/event_constants.h" 18 #include "ui/base/events/event_constants.h"
19 #include "ui/gfx/insets.h" 19 #include "ui/gfx/insets.h"
20 #include "ui/views/bubble/bubble_border_2.h"
21 #include "ui/views/bubble/bubble_delegate.h" 20 #include "ui/views/bubble/bubble_delegate.h"
22 #include "ui/views/bubble/bubble_frame_view.h" 21 #include "ui/views/bubble/bubble_frame_view.h"
23 #include "ui/views/controls/label.h" 22 #include "ui/views/controls/label.h"
24 #include "ui/views/layout/fill_layout.h" 23 #include "ui/views/layout/fill_layout.h"
25 #include "ui/views/widget/widget.h" 24 #include "ui/views/widget/widget.h"
26 25
27 namespace ash { 26 namespace ash {
28 namespace internal { 27 namespace internal {
29 namespace { 28 namespace {
30 const int kTooltipTopBottomMargin = 3; 29 const int kTooltipTopBottomMargin = 3;
31 const int kTooltipLeftRightMargin = 10; 30 const int kTooltipLeftRightMargin = 10;
32 const int kTooltipAppearanceDelay = 200; // msec 31 const int kTooltipAppearanceDelay = 200; // msec
33 const int kTooltipMinHeight = 29 - 2 * kTooltipTopBottomMargin; 32 const int kTooltipMinHeight = 29 - 2 * kTooltipTopBottomMargin;
34 const SkColor kTooltipTextColor = SkColorSetRGB(0x22, 0x22, 0x22); 33 const SkColor kTooltipTextColor = SkColorSetRGB(0x22, 0x22, 0x22);
35 34
36 // The maximum width of the tooltip bubble. Borrowed the value from 35 // The maximum width of the tooltip bubble. Borrowed the value from
37 // ash/tooltip/tooltip_controller.cc 36 // ash/tooltip/tooltip_controller.cc
38 const int kTooltipMaxWidth = 250; 37 const int kTooltipMaxWidth = 250;
39 38
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. 39 // The distance between the arrow tip and edge of the anchor view.
45 const int kArrowOffset = 10; 40 const int kArrowOffset = 10;
46 41
47 views::BubbleBorder::ArrowLocation GetArrowLocation(ShelfAlignment alignment) { 42 views::BubbleBorder::ArrowLocation GetArrowLocation(ShelfAlignment alignment) {
48 switch (alignment) { 43 switch (alignment) {
49 case SHELF_ALIGNMENT_LEFT: 44 case SHELF_ALIGNMENT_LEFT:
50 return views::BubbleBorder::LEFT_BOTTOM; 45 return views::BubbleBorder::LEFT_CENTER;
51 case SHELF_ALIGNMENT_RIGHT: 46 case SHELF_ALIGNMENT_RIGHT:
52 return views::BubbleBorder::RIGHT_BOTTOM; 47 return views::BubbleBorder::RIGHT_CENTER;
53 case SHELF_ALIGNMENT_BOTTOM: 48 case SHELF_ALIGNMENT_BOTTOM:
54 return views::BubbleBorder::BOTTOM_RIGHT; 49 return views::BubbleBorder::BOTTOM_CENTER;
55 } 50 }
56 51
57 return views::BubbleBorder::NONE; 52 return views::BubbleBorder::NONE;
58 } 53 }
59 } // namespace 54 } // namespace
60 55
61 // The implementation of tooltip of the launcher. 56 // The implementation of tooltip of the launcher.
62 class LauncherTooltipManager::LauncherTooltipBubble 57 class LauncherTooltipManager::LauncherTooltipBubble
63 : public views::BubbleDelegateView { 58 : public views::BubbleDelegateView {
64 public: 59 public:
65 LauncherTooltipBubble(views::View* anchor, 60 LauncherTooltipBubble(views::View* anchor,
66 views::BubbleBorder::ArrowLocation arrow_location, 61 views::BubbleBorder::ArrowLocation arrow_location,
67 LauncherTooltipManager* host); 62 LauncherTooltipManager* host);
68 63
69 void SetText(const string16& text); 64 void SetText(const string16& text);
70 void Close(); 65 void Close();
71 66
72 private: 67 private:
73 // Overridden from views::BubbleDelegateView:
74 virtual gfx::Rect GetBubbleBounds() OVERRIDE;
75
76 // views::WidgetDelegate overrides: 68 // views::WidgetDelegate overrides:
77 virtual void WindowClosing() OVERRIDE; 69 virtual void WindowClosing() OVERRIDE;
78 70
79 // views::View overrides: 71 // views::View overrides:
80 virtual gfx::Size GetPreferredSize() OVERRIDE; 72 virtual gfx::Size GetPreferredSize() OVERRIDE;
81 73
82 LauncherTooltipManager* host_; 74 LauncherTooltipManager* host_;
83 views::Label* label_; 75 views::Label* label_;
84 views::BubbleBorder2* bubble_border_;
85 76
86 DISALLOW_COPY_AND_ASSIGN(LauncherTooltipBubble); 77 DISALLOW_COPY_AND_ASSIGN(LauncherTooltipBubble);
87 }; 78 };
88 79
89 LauncherTooltipManager::LauncherTooltipBubble::LauncherTooltipBubble( 80 LauncherTooltipManager::LauncherTooltipBubble::LauncherTooltipBubble(
90 views::View* anchor, 81 views::View* anchor,
91 views::BubbleBorder::ArrowLocation arrow_location, 82 views::BubbleBorder::ArrowLocation arrow_location,
92 LauncherTooltipManager* host) 83 LauncherTooltipManager* host)
93 : views::BubbleDelegateView(anchor, arrow_location), 84 : views::BubbleDelegateView(anchor, arrow_location),
94 host_(host), 85 host_(host) {
95 bubble_border_(NULL) { 86 set_anchor_insets(gfx::Insets(kArrowOffset, kArrowOffset, kArrowOffset,
87 kArrowOffset));
96 set_close_on_esc(false); 88 set_close_on_esc(false);
97 set_close_on_deactivate(false); 89 set_close_on_deactivate(false);
98 set_use_focusless(true); 90 set_use_focusless(true);
99 set_accept_events(false); 91 set_accept_events(false);
100 set_margins(gfx::Insets(kTooltipTopBottomMargin, kTooltipLeftRightMargin, 92 set_margins(gfx::Insets(kTooltipTopBottomMargin, kTooltipLeftRightMargin,
101 kTooltipTopBottomMargin, kTooltipLeftRightMargin)); 93 kTooltipTopBottomMargin, kTooltipLeftRightMargin));
94 set_shadow(views::BubbleBorder::SMALL_SHADOW);
102 SetLayoutManager(new views::FillLayout()); 95 SetLayoutManager(new views::FillLayout());
103 // The anchor may not have the widget in tests. 96 // The anchor may not have the widget in tests.
104 if (anchor->GetWidget() && anchor->GetWidget()->GetNativeView()) { 97 if (anchor->GetWidget() && anchor->GetWidget()->GetNativeView()) {
105 aura::RootWindow* root_window = 98 aura::RootWindow* root_window =
106 anchor->GetWidget()->GetNativeView()->GetRootWindow(); 99 anchor->GetWidget()->GetNativeView()->GetRootWindow();
107 set_parent_window(ash::Shell::GetInstance()->GetContainer( 100 set_parent_window(ash::Shell::GetInstance()->GetContainer(
108 root_window, ash::internal::kShellWindowId_SettingBubbleContainer)); 101 root_window, ash::internal::kShellWindowId_SettingBubbleContainer));
109 } 102 }
110 label_ = new views::Label; 103 label_ = new views::Label;
111 label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); 104 label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
112 label_->SetEnabledColor(kTooltipTextColor); 105 label_->SetEnabledColor(kTooltipTextColor);
113 label_->SetElideBehavior(views::Label::ELIDE_AT_END); 106 label_->SetElideBehavior(views::Label::ELIDE_AT_END);
114 AddChildView(label_); 107 AddChildView(label_);
115 views::BubbleDelegateView::CreateBubble(this); 108 views::BubbleDelegateView::CreateBubble(this);
116 bubble_border_ = new views::BubbleBorder2(views::BubbleBorder::BOTTOM_RIGHT);
117 bubble_border_->SetShadow(gfx::ShadowValue(
118 gfx::Point(0, 5), kShadowWidth, SkColorSetARGB(0x72, 0, 0, 0)));
119 bubble_border_->set_arrow_width(kArrowWidth);
120 bubble_border_->set_arrow_height(kArrowHeight);
121 set_anchor_insets(gfx::Insets(kArrowOffset, kArrowOffset, kArrowOffset,
122 kArrowOffset));
123 GetBubbleFrameView()->SetBubbleBorder(bubble_border_);
124
125 // BubbleBorder2 paints its own background.
126 GetBubbleFrameView()->set_background(NULL);
127 } 109 }
128 110
129 void LauncherTooltipManager::LauncherTooltipBubble::SetText( 111 void LauncherTooltipManager::LauncherTooltipBubble::SetText(
130 const string16& text) { 112 const string16& text) {
131 label_->SetText(text); 113 label_->SetText(text);
132 SizeToContents(); 114 SizeToContents();
133 } 115 }
134 116
135 void LauncherTooltipManager::LauncherTooltipBubble::Close() { 117 void LauncherTooltipManager::LauncherTooltipBubble::Close() {
136 if (GetWidget()) { 118 if (GetWidget()) {
137 host_ = NULL; 119 host_ = NULL;
138 GetWidget()->Close(); 120 GetWidget()->Close();
139 } 121 }
140 } 122 }
141 123
142 gfx::Rect LauncherTooltipManager::LauncherTooltipBubble::GetBubbleBounds() {
143 // This happens before replacing the default border.
144 if (!bubble_border_)
145 return views::BubbleDelegateView::GetBubbleBounds();
146
147 const gfx::Rect anchor_rect = GetAnchorRect();
148 gfx::Rect bubble_rect = GetBubbleFrameView()->GetUpdatedWindowBounds(
149 anchor_rect,
150 GetPreferredSize(),
151 false /* try_mirroring_arrow */);
152
153 const gfx::Point old_offset = bubble_border_->offset();
154 bubble_rect = bubble_border_->ComputeOffsetAndUpdateBubbleRect(bubble_rect,
155 anchor_rect);
156
157 // Repaints border if arrow offset is changed.
158 if (bubble_border_->offset() != old_offset)
159 GetBubbleFrameView()->SchedulePaint();
160
161 return bubble_rect;
162 }
163
164 void LauncherTooltipManager::LauncherTooltipBubble::WindowClosing() { 124 void LauncherTooltipManager::LauncherTooltipBubble::WindowClosing() {
165 views::BubbleDelegateView::WindowClosing(); 125 views::BubbleDelegateView::WindowClosing();
166 if (host_) 126 if (host_)
167 host_->OnBubbleClosed(this); 127 host_->OnBubbleClosed(this);
168 } 128 }
169 129
170 gfx::Size LauncherTooltipManager::LauncherTooltipBubble::GetPreferredSize() { 130 gfx::Size LauncherTooltipManager::LauncherTooltipBubble::GetPreferredSize() {
171 gfx::Size pref_size = views::BubbleDelegateView::GetPreferredSize(); 131 gfx::Size pref_size = views::BubbleDelegateView::GetPreferredSize();
172 if (pref_size.height() < kTooltipMinHeight) 132 if (pref_size.height() < kTooltipMinHeight)
173 pref_size.set_height(kTooltipMinHeight); 133 pref_size.set_height(kTooltipMinHeight);
(...skipping 23 matching lines...) Expand all
197 Close(); 157 Close();
198 if (shelf_layout_manager_) 158 if (shelf_layout_manager_)
199 shelf_layout_manager_->RemoveObserver(this); 159 shelf_layout_manager_->RemoveObserver(this);
200 if (Shell::HasInstance()) 160 if (Shell::HasInstance())
201 Shell::GetInstance()->RemoveEnvEventFilter(this); 161 Shell::GetInstance()->RemoveEnvEventFilter(this);
202 } 162 }
203 163
204 void LauncherTooltipManager::ShowDelayed(views::View* anchor, 164 void LauncherTooltipManager::ShowDelayed(views::View* anchor,
205 const string16& text) { 165 const string16& text) {
206 if (view_) { 166 if (view_) {
207 if (timer_.get() && timer_->IsRunning()) 167 if (timer_.get() && timer_->IsRunning()) {
208 return; 168 return;
209 else { 169 } else {
210 CancelHidingAnimation(); 170 CancelHidingAnimation();
211 Close(); 171 Close();
212 } 172 }
213 } 173 }
214 174
215 if (shelf_layout_manager_ && !shelf_layout_manager_->IsVisible()) 175 if (shelf_layout_manager_ && !shelf_layout_manager_->IsVisible())
216 return; 176 return;
217 177
218 CreateBubble(anchor, text); 178 CreateBubble(anchor, text);
219 ResetTimer(); 179 ResetTimer();
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 view_->SetText(text_); 369 view_->SetText(text_);
410 370
411 gfx::NativeView native_view = widget_->GetNativeView(); 371 gfx::NativeView native_view = widget_->GetNativeView();
412 SetWindowVisibilityAnimationType( 372 SetWindowVisibilityAnimationType(
413 native_view, WINDOW_VISIBILITY_ANIMATION_TYPE_VERTICAL); 373 native_view, WINDOW_VISIBILITY_ANIMATION_TYPE_VERTICAL);
414 SetWindowVisibilityAnimationTransition(native_view, ANIMATE_HIDE); 374 SetWindowVisibilityAnimationTransition(native_view, ANIMATE_HIDE);
415 } 375 }
416 376
417 } // namespace internal 377 } // namespace internal
418 } // namespace ash 378 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | ash/launcher/overflow_bubble.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698