OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "views/bubble/bubble_delegate.h" | 5 #include "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 "views/bubble/bubble_frame_view.h" | 8 #include "views/bubble/bubble_frame_view.h" |
9 #include "views/widget/widget.h" | 9 #include "views/widget/widget.h" |
10 | 10 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 anchor_view_(NULL), | 80 anchor_view_(NULL), |
81 arrow_location_(BubbleBorder::TOP_LEFT), | 81 arrow_location_(BubbleBorder::TOP_LEFT), |
82 color_(SK_ColorWHITE), | 82 color_(SK_ColorWHITE), |
83 border_widget_(NULL), | 83 border_widget_(NULL), |
84 use_focusless_(false) { | 84 use_focusless_(false) { |
85 set_background(views::Background::CreateSolidBackground(color_)); | 85 set_background(views::Background::CreateSolidBackground(color_)); |
86 AddAccelerator(Accelerator(ui::VKEY_ESCAPE, 0)); | 86 AddAccelerator(Accelerator(ui::VKEY_ESCAPE, 0)); |
87 } | 87 } |
88 | 88 |
89 BubbleDelegateView::BubbleDelegateView( | 89 BubbleDelegateView::BubbleDelegateView( |
90 View* anchor_view, | 90 const View* anchor_view, |
91 BubbleBorder::ArrowLocation arrow_location, | 91 BubbleBorder::ArrowLocation arrow_location, |
92 const SkColor& color) | 92 const SkColor& color) |
93 : close_on_esc_(true), | 93 : close_on_esc_(true), |
94 close_on_deactivate_(true), | 94 close_on_deactivate_(true), |
95 allow_bubble_offscreen_(false), | 95 allow_bubble_offscreen_(false), |
96 anchor_view_(anchor_view), | 96 anchor_view_(anchor_view), |
97 arrow_location_(arrow_location), | 97 arrow_location_(arrow_location), |
98 color_(color), | 98 color_(color), |
99 original_opacity_(255), | 99 original_opacity_(255), |
100 border_widget_(NULL), | 100 border_widget_(NULL), |
101 use_focusless_(false) { | 101 use_focusless_(false) { |
102 set_background(views::Background::CreateSolidBackground(color_)); | 102 set_background(views::Background::CreateSolidBackground(color_)); |
103 AddAccelerator(Accelerator(ui::VKEY_ESCAPE, 0)); | 103 AddAccelerator(Accelerator(ui::VKEY_ESCAPE, 0)); |
104 } | 104 } |
105 | 105 |
106 BubbleDelegateView::~BubbleDelegateView() { | 106 BubbleDelegateView::~BubbleDelegateView() { |
107 if (border_widget_) | 107 if (border_widget_) |
108 border_widget_->Close(); | 108 border_widget_->Close(); |
109 } | 109 } |
110 | 110 |
111 // static | 111 // static |
112 Widget* BubbleDelegateView::CreateBubble(BubbleDelegateView* bubble_delegate) { | 112 Widget* BubbleDelegateView::CreateBubble(BubbleDelegateView* bubble_delegate) { |
113 bubble_delegate->Init(); | 113 bubble_delegate->Init(); |
114 Widget* parent_widget = bubble_delegate->anchor_view() ? | 114 Widget* parent = bubble_delegate->anchor_view() ? |
115 bubble_delegate->anchor_view()->GetWidget() : NULL; | 115 const_cast<Widget*>(bubble_delegate->anchor_view()->GetWidget()) : NULL; |
116 Widget* bubble_widget = CreateBubbleWidget(bubble_delegate, parent_widget); | 116 Widget* bubble_widget = CreateBubbleWidget(bubble_delegate, parent); |
117 | 117 |
118 #if defined(OS_WIN) && !defined(USE_AURA) | 118 #if defined(OS_WIN) && !defined(USE_AURA) |
119 // First set the contents view to initialize view bounds for widget sizing. | 119 // First set the contents view to initialize view bounds for widget sizing. |
120 bubble_widget->SetContentsView(bubble_delegate->GetContentsView()); | 120 bubble_widget->SetContentsView(bubble_delegate->GetContentsView()); |
121 bubble_delegate->InitializeBorderWidget(parent_widget); | 121 bubble_delegate->border_widget_ = CreateBorderWidget(bubble_delegate, parent); |
122 bubble_widget->SetBounds(bubble_delegate->GetBubbleClientBounds()); | |
123 #else | |
124 bubble_widget->SetBounds(bubble_delegate->GetBubbleBounds()); | |
125 #endif | 122 #endif |
126 | 123 |
| 124 bubble_delegate->SizeToContents(); |
127 bubble_widget->AddObserver(bubble_delegate); | 125 bubble_widget->AddObserver(bubble_delegate); |
128 if (parent_widget && parent_widget->GetTopLevelWidget()) | 126 if (parent && parent->GetTopLevelWidget()) |
129 parent_widget->GetTopLevelWidget()->DisableInactiveRendering(); | 127 parent->GetTopLevelWidget()->DisableInactiveRendering(); |
130 return bubble_widget; | 128 return bubble_widget; |
131 } | 129 } |
132 | 130 |
133 View* BubbleDelegateView::GetInitiallyFocusedView() { | 131 View* BubbleDelegateView::GetInitiallyFocusedView() { |
134 return this; | 132 return this; |
135 } | 133 } |
136 | 134 |
137 BubbleDelegateView* BubbleDelegateView::AsBubbleDelegate() { | 135 BubbleDelegateView* BubbleDelegateView::AsBubbleDelegate() { |
138 return this; | 136 return this; |
139 } | 137 } |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 | 215 |
218 bool BubbleDelegateView::AcceleratorPressed(const Accelerator& accelerator) { | 216 bool BubbleDelegateView::AcceleratorPressed(const Accelerator& accelerator) { |
219 if (!close_on_esc() || accelerator.key_code() != ui::VKEY_ESCAPE) | 217 if (!close_on_esc() || accelerator.key_code() != ui::VKEY_ESCAPE) |
220 return false; | 218 return false; |
221 if (fade_animation_.get()) | 219 if (fade_animation_.get()) |
222 fade_animation_->Reset(); | 220 fade_animation_->Reset(); |
223 GetWidget()->Close(); | 221 GetWidget()->Close(); |
224 return true; | 222 return true; |
225 } | 223 } |
226 | 224 |
227 void BubbleDelegateView::Init() {} | |
228 | |
229 void BubbleDelegateView::AnimationEnded(const ui::Animation* animation) { | 225 void BubbleDelegateView::AnimationEnded(const ui::Animation* animation) { |
230 DCHECK_EQ(animation, fade_animation_.get()); | 226 DCHECK_EQ(animation, fade_animation_.get()); |
231 bool closed = fade_animation_->GetCurrentValue() == 0; | 227 bool closed = fade_animation_->GetCurrentValue() == 0; |
232 fade_animation_->Reset(); | 228 fade_animation_->Reset(); |
233 if (closed) | 229 if (closed) |
234 GetWidget()->Close(); | 230 GetWidget()->Close(); |
235 } | 231 } |
236 | 232 |
237 void BubbleDelegateView::AnimationProgressed(const ui::Animation* animation) { | 233 void BubbleDelegateView::AnimationProgressed(const ui::Animation* animation) { |
238 DCHECK_EQ(animation, fade_animation_.get()); | 234 DCHECK_EQ(animation, fade_animation_.get()); |
(...skipping 10 matching lines...) Expand all Loading... |
249 SetWindowLong(hwnd, GWL_EXSTYLE, style ^ WS_EX_LAYERED); | 245 SetWindowLong(hwnd, GWL_EXSTYLE, style ^ WS_EX_LAYERED); |
250 SetLayeredWindowAttributes(hwnd, 0, opacity, LWA_ALPHA); | 246 SetLayeredWindowAttributes(hwnd, 0, opacity, LWA_ALPHA); |
251 // Update the border widget's opacity. | 247 // Update the border widget's opacity. |
252 border_widget_->SetOpacity(opacity); | 248 border_widget_->SetOpacity(opacity); |
253 border_widget_->non_client_view()->SchedulePaint(); | 249 border_widget_->non_client_view()->SchedulePaint(); |
254 #endif | 250 #endif |
255 GetWidget()->SetOpacity(opacity); | 251 GetWidget()->SetOpacity(opacity); |
256 SchedulePaint(); | 252 SchedulePaint(); |
257 } | 253 } |
258 | 254 |
| 255 void BubbleDelegateView::Init() {} |
| 256 |
| 257 void BubbleDelegateView::SizeToContents() { |
| 258 #if defined(OS_WIN) && !defined(USE_AURA) |
| 259 border_widget_->SetBounds(GetBubbleBounds()); |
| 260 GetWidget()->SetBounds(GetBubbleClientBounds()); |
| 261 #else |
| 262 GetWidget()->SetBounds(GetBubbleBounds()); |
| 263 #endif |
| 264 } |
| 265 |
259 BubbleFrameView* BubbleDelegateView::GetBubbleFrameView() const { | 266 BubbleFrameView* BubbleDelegateView::GetBubbleFrameView() const { |
260 const Widget* widget = border_widget_ ? border_widget_ : GetWidget(); | 267 const Widget* widget = border_widget_ ? border_widget_ : GetWidget(); |
261 return static_cast<BubbleFrameView*>(widget->non_client_view()->frame_view()); | 268 return static_cast<BubbleFrameView*>(widget->non_client_view()->frame_view()); |
262 } | 269 } |
263 | 270 |
264 gfx::Rect BubbleDelegateView::GetBubbleBounds() { | 271 gfx::Rect BubbleDelegateView::GetBubbleBounds() { |
265 // The argument rect has its origin at the bubble's arrow anchor point; | 272 // The argument rect has its origin at the bubble's arrow anchor point; |
266 // its size is the preferred size of the bubble's client view (this view). | 273 // its size is the preferred size of the bubble's client view (this view). |
267 return GetBubbleFrameView()->GetWindowBoundsForClientBounds( | 274 return GetBubbleFrameView()->GetWindowBoundsForClientBounds( |
268 gfx::Rect(GetAnchorPoint(), GetPreferredSize())); | 275 gfx::Rect(GetAnchorPoint(), GetPreferredSize())); |
269 } | 276 } |
270 | 277 |
271 #if defined(OS_WIN) && !defined(USE_AURA) | 278 #if defined(OS_WIN) && !defined(USE_AURA) |
272 void BubbleDelegateView::InitializeBorderWidget(Widget* parent_widget) { | |
273 border_widget_ = CreateBorderWidget(this, parent_widget); | |
274 border_widget_->SetBounds(GetBubbleBounds()); | |
275 } | |
276 | |
277 gfx::Rect BubbleDelegateView::GetBubbleClientBounds() const { | 279 gfx::Rect BubbleDelegateView::GetBubbleClientBounds() const { |
278 gfx::Rect client_bounds(GetBubbleFrameView()->GetBoundsForClientView()); | 280 gfx::Rect client_bounds(GetBubbleFrameView()->GetBoundsForClientView()); |
279 client_bounds.Offset(border_widget_->GetWindowScreenBounds().origin()); | 281 client_bounds.Offset(border_widget_->GetWindowScreenBounds().origin()); |
280 return client_bounds; | 282 return client_bounds; |
281 } | 283 } |
282 #endif | 284 #endif |
283 | 285 |
284 } // namespace views | 286 } // namespace views |
OLD | NEW |