OLD | NEW |
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; |
30 | 34 |
31 // The maximum width of the tooltip bubble. Borrowed the value from | 35 // The maximum width of the tooltip bubble. Borrowed the value from |
32 // ash/tooltip/tooltip_controller.cc | 36 // ash/tooltip/tooltip_controller.cc |
33 const int kTooltipMaxWidth = 400; | 37 const int kTooltipMaxWidth = 250; |
| 38 |
| 39 // Bubble border metrics |
| 40 const int kCornerRadius = 1; |
| 41 const int kArrowHeight = 7; |
| 42 const int kArrowWidth = 15; |
| 43 const int kShadowWidth = 8; |
34 | 44 |
35 views::BubbleBorder::ArrowLocation GetArrowLocation(ShelfAlignment alignment) { | 45 views::BubbleBorder::ArrowLocation GetArrowLocation(ShelfAlignment alignment) { |
36 switch (alignment) { | 46 switch (alignment) { |
37 case SHELF_ALIGNMENT_LEFT: | 47 case SHELF_ALIGNMENT_LEFT: |
38 return views::BubbleBorder::LEFT_BOTTOM; | 48 return views::BubbleBorder::LEFT_BOTTOM; |
39 case SHELF_ALIGNMENT_RIGHT: | 49 case SHELF_ALIGNMENT_RIGHT: |
40 return views::BubbleBorder::RIGHT_BOTTOM; | 50 return views::BubbleBorder::RIGHT_BOTTOM; |
41 case SHELF_ALIGNMENT_BOTTOM: | 51 case SHELF_ALIGNMENT_BOTTOM: |
42 return views::BubbleBorder::BOTTOM_RIGHT; | 52 return views::BubbleBorder::BOTTOM_RIGHT; |
43 } | 53 } |
44 | 54 |
45 return views::BubbleBorder::NONE; | 55 return views::BubbleBorder::NONE; |
46 } | 56 } |
47 } // namespace | 57 } // namespace |
48 | 58 |
49 // The implementation of tooltip of the launcher. | 59 // The implementation of tooltip of the launcher. |
50 class LauncherTooltipManager::LauncherTooltipBubble | 60 class LauncherTooltipManager::LauncherTooltipBubble |
51 : public views::BubbleDelegateView { | 61 : public views::BubbleDelegateView { |
52 public: | 62 public: |
53 LauncherTooltipBubble(views::View* anchor, | 63 LauncherTooltipBubble(views::View* anchor, |
54 views::BubbleBorder::ArrowLocation arrow_location, | 64 views::BubbleBorder::ArrowLocation arrow_location, |
55 LauncherTooltipManager* host); | 65 LauncherTooltipManager* host); |
56 | 66 |
57 void SetText(const string16& text); | 67 void SetText(const string16& text); |
58 void Close(); | 68 void Close(); |
59 | 69 |
60 private: | 70 private: |
| 71 // Overridden from views::BubbleDelegateView: |
| 72 virtual gfx::Rect GetBubbleBounds() OVERRIDE; |
| 73 |
61 // views::WidgetDelegate overrides: | 74 // views::WidgetDelegate overrides: |
62 virtual void WindowClosing() OVERRIDE; | 75 virtual void WindowClosing() OVERRIDE; |
63 | 76 |
| 77 // views::View overrides: |
| 78 virtual gfx::Size GetPreferredSize() OVERRIDE; |
| 79 |
64 LauncherTooltipManager* host_; | 80 LauncherTooltipManager* host_; |
65 views::Label* label_; | 81 views::Label* label_; |
| 82 views::BubbleBorderGeometric* bubble_border_; |
66 }; | 83 }; |
67 | 84 |
68 LauncherTooltipManager::LauncherTooltipBubble::LauncherTooltipBubble( | 85 LauncherTooltipManager::LauncherTooltipBubble::LauncherTooltipBubble( |
69 views::View* anchor, | 86 views::View* anchor, |
70 views::BubbleBorder::ArrowLocation arrow_location, | 87 views::BubbleBorder::ArrowLocation arrow_location, |
71 LauncherTooltipManager* host) | 88 LauncherTooltipManager* host) |
72 : views::BubbleDelegateView(anchor, arrow_location), | 89 : views::BubbleDelegateView(anchor, arrow_location), |
73 host_(host) { | 90 host_(host), |
| 91 bubble_border_(NULL) { |
74 set_close_on_esc(false); | 92 set_close_on_esc(false); |
75 set_close_on_deactivate(false); | 93 set_close_on_deactivate(false); |
76 set_use_focusless(true); | 94 set_use_focusless(true); |
77 set_margins(gfx::Insets(kTooltipMargin, kTooltipMargin, kTooltipMargin, | 95 set_margins(gfx::Insets(kTooltipTopBottomMargin, kTooltipLeftRightMargin, |
78 kTooltipMargin)); | 96 kTooltipTopBottomMargin, kTooltipLeftRightMargin)); |
79 SetLayoutManager(new views::FillLayout()); | 97 SetLayoutManager(new views::FillLayout()); |
80 // The anchor may not have the widget in tests. | 98 // The anchor may not have the widget in tests. |
81 if (anchor->GetWidget() && anchor->GetWidget()->GetNativeView()) { | 99 if (anchor->GetWidget() && anchor->GetWidget()->GetNativeView()) { |
82 aura::RootWindow* root_window = | 100 aura::RootWindow* root_window = |
83 anchor->GetWidget()->GetNativeView()->GetRootWindow(); | 101 anchor->GetWidget()->GetNativeView()->GetRootWindow(); |
84 set_parent_window(ash::Shell::GetInstance()->GetContainer( | 102 set_parent_window(ash::Shell::GetInstance()->GetContainer( |
85 root_window, ash::internal::kShellWindowId_SettingBubbleContainer)); | 103 root_window, ash::internal::kShellWindowId_SettingBubbleContainer)); |
86 } | 104 } |
87 label_ = new views::Label; | 105 label_ = new views::Label; |
88 label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 106 label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
89 AddChildView(label_); | 107 AddChildView(label_); |
| 108 views::BubbleDelegateView::CreateBubble(this); |
| 109 bubble_border_ = new views::BubbleBorderGeometric( |
| 110 views::BubbleBorder::BOTTOM_RIGHT); |
| 111 bubble_border_->SetShadow(gfx::ShadowValue( |
| 112 gfx::Point(0, 5), kShadowWidth, SkColorSetARGB(0x72, 0, 0, 0))); |
| 113 bubble_border_->set_corner_radius(kCornerRadius); |
| 114 bubble_border_->set_arrow_width(kArrowWidth); |
| 115 bubble_border_->set_arrow_height(kArrowHeight); |
| 116 GetBubbleFrameView()->SetBubbleBorder(bubble_border_); |
90 } | 117 } |
91 | 118 |
92 void LauncherTooltipManager::LauncherTooltipBubble::SetText( | 119 void LauncherTooltipManager::LauncherTooltipBubble::SetText( |
93 const string16& text) { | 120 const string16& text) { |
94 label_->SetText(text); | 121 label_->SetText(text); |
95 label_->SetMultiLine(true); | |
96 label_->SizeToFit(kTooltipMaxWidth); | |
97 SizeToContents(); | 122 SizeToContents(); |
98 } | 123 } |
99 | 124 |
100 void LauncherTooltipManager::LauncherTooltipBubble::Close() { | 125 void LauncherTooltipManager::LauncherTooltipBubble::Close() { |
101 if (GetWidget()) { | 126 if (GetWidget()) { |
102 host_ = NULL; | 127 host_ = NULL; |
103 GetWidget()->Close(); | 128 GetWidget()->Close(); |
104 } | 129 } |
105 } | 130 } |
106 | 131 |
| 132 gfx::Rect LauncherTooltipManager::LauncherTooltipBubble::GetBubbleBounds() { |
| 133 // This happens before replacing the default border. |
| 134 if (!bubble_border_) |
| 135 return views::BubbleDelegateView::GetBubbleBounds(); |
| 136 |
| 137 const gfx::Rect anchor_rect = GetAnchorRect(); |
| 138 gfx::Rect bubble_rect = GetBubbleFrameView()->GetUpdatedWindowBounds( |
| 139 anchor_rect, |
| 140 GetPreferredSize(), |
| 141 false /* try_mirroring_arrow */); |
| 142 |
| 143 const gfx::Point old_offset = bubble_border_->offset(); |
| 144 bubble_rect = bubble_border_->ComputeOffsetAndUpdateBubbleRect(bubble_rect, |
| 145 anchor_rect); |
| 146 |
| 147 // Repaints border if arrow offset is changed. |
| 148 if (bubble_border_->offset() != old_offset) |
| 149 GetBubbleFrameView()->SchedulePaint(); |
| 150 |
| 151 return bubble_rect; |
| 152 } |
| 153 |
107 void LauncherTooltipManager::LauncherTooltipBubble::WindowClosing() { | 154 void LauncherTooltipManager::LauncherTooltipBubble::WindowClosing() { |
108 views::BubbleDelegateView::WindowClosing(); | 155 views::BubbleDelegateView::WindowClosing(); |
109 if (host_) | 156 if (host_) |
110 host_->OnBubbleClosed(this); | 157 host_->OnBubbleClosed(this); |
111 } | 158 } |
112 | 159 |
| 160 gfx::Size LauncherTooltipManager::LauncherTooltipBubble::GetPreferredSize() { |
| 161 gfx::Size pref_size = views::BubbleDelegateView::GetPreferredSize(); |
| 162 if (pref_size.height() < kTooltipMinHeight) |
| 163 pref_size.set_height(kTooltipMinHeight); |
| 164 if (pref_size.width() > kTooltipMaxWidth) |
| 165 pref_size.set_width(kTooltipMaxWidth); |
| 166 return pref_size; |
| 167 } |
| 168 |
113 LauncherTooltipManager::LauncherTooltipManager( | 169 LauncherTooltipManager::LauncherTooltipManager( |
114 ShelfAlignment alignment, | 170 ShelfAlignment alignment, |
115 ShelfLayoutManager* shelf_layout_manager, | 171 ShelfLayoutManager* shelf_layout_manager, |
116 LauncherView* launcher_view) | 172 LauncherView* launcher_view) |
117 : view_(NULL), | 173 : view_(NULL), |
118 widget_(NULL), | 174 widget_(NULL), |
119 anchor_(NULL), | 175 anchor_(NULL), |
120 alignment_(alignment), | 176 alignment_(alignment), |
121 shelf_layout_manager_(shelf_layout_manager), | 177 shelf_layout_manager_(shelf_layout_manager), |
122 launcher_view_(launcher_view) { | 178 launcher_view_(launcher_view) { |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 } | 388 } |
333 | 389 |
334 void LauncherTooltipManager::CreateBubble(views::View* anchor, | 390 void LauncherTooltipManager::CreateBubble(views::View* anchor, |
335 const string16& text) { | 391 const string16& text) { |
336 DCHECK(!view_); | 392 DCHECK(!view_); |
337 | 393 |
338 anchor_ = anchor; | 394 anchor_ = anchor; |
339 text_ = text; | 395 text_ = text; |
340 view_ = new LauncherTooltipBubble( | 396 view_ = new LauncherTooltipBubble( |
341 anchor, GetArrowLocation(alignment_), this); | 397 anchor, GetArrowLocation(alignment_), this); |
342 views::BubbleDelegateView::CreateBubble(view_); | |
343 widget_ = view_->GetWidget(); | 398 widget_ = view_->GetWidget(); |
344 view_->SetText(text_); | 399 view_->SetText(text_); |
345 | 400 |
346 gfx::NativeView native_view = widget_->GetNativeView(); | 401 gfx::NativeView native_view = widget_->GetNativeView(); |
347 SetWindowVisibilityAnimationType( | 402 SetWindowVisibilityAnimationType( |
348 native_view, WINDOW_VISIBILITY_ANIMATION_TYPE_VERTICAL); | 403 native_view, WINDOW_VISIBILITY_ANIMATION_TYPE_VERTICAL); |
349 SetWindowVisibilityAnimationTransition(native_view, ANIMATE_HIDE); | 404 SetWindowVisibilityAnimationTransition(native_view, ANIMATE_HIDE); |
350 } | 405 } |
351 | 406 |
352 } // namespace internal | 407 } // namespace internal |
353 } // namespace ash | 408 } // namespace ash |
OLD | NEW |