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 "ui/views/bubble/bubble_delegate.h" | 5 #include "ui/views/bubble/bubble_delegate.h" |
6 | 6 |
7 #include "ui/base/animation/slide_animation.h" | 7 #include "ui/base/animation/slide_animation.h" |
8 #include "ui/gfx/color_utils.h" | 8 #include "ui/gfx/color_utils.h" |
9 #include "ui/gfx/rect.h" | 9 #include "ui/gfx/rect.h" |
10 #include "ui/native_theme/native_theme.h" | 10 #include "ui/native_theme/native_theme.h" |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
100 | 100 |
101 } // namespace | 101 } // namespace |
102 | 102 |
103 BubbleDelegateView::BubbleDelegateView() | 103 BubbleDelegateView::BubbleDelegateView() |
104 : close_on_esc_(true), | 104 : close_on_esc_(true), |
105 close_on_deactivate_(true), | 105 close_on_deactivate_(true), |
106 anchor_view_(NULL), | 106 anchor_view_(NULL), |
107 anchor_widget_(NULL), | 107 anchor_widget_(NULL), |
108 move_with_anchor_(false), | 108 move_with_anchor_(false), |
109 arrow_(BubbleBorder::TOP_LEFT), | 109 arrow_(BubbleBorder::TOP_LEFT), |
110 arrow_offset_(0), | |
110 shadow_(BubbleBorder::SMALL_SHADOW), | 111 shadow_(BubbleBorder::SMALL_SHADOW), |
111 color_explicitly_set_(false), | 112 color_explicitly_set_(false), |
112 margins_(kDefaultMargin, kDefaultMargin, kDefaultMargin, kDefaultMargin), | 113 margins_(kDefaultMargin, kDefaultMargin, kDefaultMargin, kDefaultMargin), |
113 original_opacity_(255), | 114 original_opacity_(255), |
114 border_widget_(NULL), | 115 border_widget_(NULL), |
115 use_focusless_(false), | 116 use_focusless_(false), |
116 accept_events_(true), | 117 accept_events_(true), |
117 border_accepts_events_(true), | 118 border_accepts_events_(true), |
118 adjust_if_offscreen_(true), | 119 adjust_if_offscreen_(true), |
119 parent_window_(NULL) { | 120 parent_window_(NULL) { |
120 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); | 121 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); |
121 UpdateColorsFromTheme(GetNativeTheme()); | 122 UpdateColorsFromTheme(GetNativeTheme()); |
122 } | 123 } |
123 | 124 |
124 BubbleDelegateView::BubbleDelegateView( | 125 BubbleDelegateView::BubbleDelegateView( |
125 View* anchor_view, | 126 View* anchor_view, |
126 BubbleBorder::Arrow arrow) | 127 BubbleBorder::Arrow arrow) |
127 : close_on_esc_(true), | 128 : close_on_esc_(true), |
128 close_on_deactivate_(true), | 129 close_on_deactivate_(true), |
129 anchor_view_(anchor_view), | 130 anchor_view_(anchor_view), |
130 anchor_widget_(NULL), | 131 anchor_widget_(NULL), |
131 move_with_anchor_(false), | 132 move_with_anchor_(false), |
132 arrow_(arrow), | 133 arrow_(arrow), |
134 arrow_offset_(0), | |
133 shadow_(BubbleBorder::SMALL_SHADOW), | 135 shadow_(BubbleBorder::SMALL_SHADOW), |
134 color_explicitly_set_(false), | 136 color_explicitly_set_(false), |
135 margins_(kDefaultMargin, kDefaultMargin, kDefaultMargin, kDefaultMargin), | 137 margins_(kDefaultMargin, kDefaultMargin, kDefaultMargin, kDefaultMargin), |
136 original_opacity_(255), | 138 original_opacity_(255), |
137 border_widget_(NULL), | 139 border_widget_(NULL), |
138 use_focusless_(false), | 140 use_focusless_(false), |
139 accept_events_(true), | 141 accept_events_(true), |
140 border_accepts_events_(true), | 142 border_accepts_events_(true), |
141 adjust_if_offscreen_(true), | 143 adjust_if_offscreen_(true), |
142 parent_window_(NULL) { | 144 parent_window_(NULL) { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
183 | 185 |
184 View* BubbleDelegateView::GetContentsView() { | 186 View* BubbleDelegateView::GetContentsView() { |
185 return this; | 187 return this; |
186 } | 188 } |
187 | 189 |
188 NonClientFrameView* BubbleDelegateView::CreateNonClientFrameView( | 190 NonClientFrameView* BubbleDelegateView::CreateNonClientFrameView( |
189 Widget* widget) { | 191 Widget* widget) { |
190 BubbleFrameView* frame = new BubbleFrameView(margins()); | 192 BubbleFrameView* frame = new BubbleFrameView(margins()); |
191 const BubbleBorder::Arrow adjusted_arrow = base::i18n::IsRTL() ? | 193 const BubbleBorder::Arrow adjusted_arrow = base::i18n::IsRTL() ? |
192 BubbleBorder::horizontal_mirror(arrow()) : arrow(); | 194 BubbleBorder::horizontal_mirror(arrow()) : arrow(); |
193 frame->SetBubbleBorder(new BubbleBorder(adjusted_arrow, shadow(), color())); | 195 BubbleBorder* border = new BubbleBorder(adjusted_arrow, shadow(), color()); |
196 if (arrow_offset_) | |
197 border->set_arrow_offset(arrow_offset_); | |
198 frame->SetBubbleBorder(border); | |
194 return frame; | 199 return frame; |
195 } | 200 } |
196 | 201 |
197 void BubbleDelegateView::OnWidgetDestroying(Widget* widget) { | 202 void BubbleDelegateView::OnWidgetDestroying(Widget* widget) { |
198 if (anchor_widget() == widget) { | 203 if (anchor_widget() == widget) { |
199 anchor_widget_->RemoveObserver(this); | 204 anchor_widget_->RemoveObserver(this); |
200 anchor_view_ = NULL; | 205 anchor_view_ = NULL; |
201 anchor_widget_ = NULL; | 206 anchor_widget_ = NULL; |
202 } | 207 } |
203 } | 208 } |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
260 if (border_widget_) | 265 if (border_widget_) |
261 border_widget_->SetOpacity(original_opacity_); | 266 border_widget_->SetOpacity(original_opacity_); |
262 GetWidget()->SetOpacity(original_opacity_); | 267 GetWidget()->SetOpacity(original_opacity_); |
263 } | 268 } |
264 | 269 |
265 void BubbleDelegateView::SetAlignment(BubbleBorder::BubbleAlignment alignment) { | 270 void BubbleDelegateView::SetAlignment(BubbleBorder::BubbleAlignment alignment) { |
266 GetBubbleFrameView()->bubble_border()->set_alignment(alignment); | 271 GetBubbleFrameView()->bubble_border()->set_alignment(alignment); |
267 SizeToContents(); | 272 SizeToContents(); |
268 } | 273 } |
269 | 274 |
275 void BubbleDelegateView::SetArrowOffset(int offset) { | |
276 arrow_offset_ = offset; | |
277 if (GetBubbleFrameView() && GetBubbleFrameView()->bubble_border()) | |
msw
2013/05/21 01:41:27
You should be able to do this in the PopupMessage:
Mr4D (OOO till 08-26)
2013/05/21 17:26:40
Well - it appears that you have never tried this b
| |
278 GetBubbleFrameView()->bubble_border()->set_arrow_offset(offset); | |
279 } | |
280 | |
270 bool BubbleDelegateView::AcceleratorPressed( | 281 bool BubbleDelegateView::AcceleratorPressed( |
271 const ui::Accelerator& accelerator) { | 282 const ui::Accelerator& accelerator) { |
272 if (!close_on_esc() || accelerator.key_code() != ui::VKEY_ESCAPE) | 283 if (!close_on_esc() || accelerator.key_code() != ui::VKEY_ESCAPE) |
273 return false; | 284 return false; |
274 if (fade_animation_.get()) | 285 if (fade_animation_.get()) |
275 fade_animation_->Reset(); | 286 fade_animation_->Reset(); |
276 GetWidget()->Close(); | 287 GetWidget()->Close(); |
277 return true; | 288 return true; |
278 } | 289 } |
279 | 290 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
354 #if defined(OS_WIN) && !defined(USE_AURA) | 365 #if defined(OS_WIN) && !defined(USE_AURA) |
355 gfx::Rect BubbleDelegateView::GetBubbleClientBounds() const { | 366 gfx::Rect BubbleDelegateView::GetBubbleClientBounds() const { |
356 gfx::Rect client_bounds(GetBubbleFrameView()->GetBoundsForClientView()); | 367 gfx::Rect client_bounds(GetBubbleFrameView()->GetBoundsForClientView()); |
357 client_bounds.Offset( | 368 client_bounds.Offset( |
358 border_widget_->GetWindowBoundsInScreen().OffsetFromOrigin()); | 369 border_widget_->GetWindowBoundsInScreen().OffsetFromOrigin()); |
359 return client_bounds; | 370 return client_bounds; |
360 } | 371 } |
361 #endif | 372 #endif |
362 | 373 |
363 } // namespace views | 374 } // namespace views |
OLD | NEW |