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 "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/views/bubble/bubble_frame_view.h" | 8 #include "ui/views/bubble/bubble_frame_view.h" |
9 #include "ui/views/widget/widget.h" | 9 #include "ui/views/widget/widget.h" |
10 | 10 |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
147 } | 147 } |
148 | 148 |
149 void BubbleDelegateView::OnWidgetActivationChanged(Widget* widget, | 149 void BubbleDelegateView::OnWidgetActivationChanged(Widget* widget, |
150 bool active) { | 150 bool active) { |
151 if (close_on_deactivate() && widget == GetWidget() && !active) { | 151 if (close_on_deactivate() && widget == GetWidget() && !active) { |
152 GetWidget()->RemoveObserver(this); | 152 GetWidget()->RemoveObserver(this); |
153 GetWidget()->Close(); | 153 GetWidget()->Close(); |
154 } | 154 } |
155 } | 155 } |
156 | 156 |
157 gfx::Point BubbleDelegateView::GetAnchorPoint() { | 157 gfx::Rect BubbleDelegateView::GetAnchorRect() { |
158 if (!anchor_view()) | 158 if (!anchor_view()) |
159 return gfx::Point(); | 159 return gfx::Rect(); |
160 | 160 |
161 BubbleBorder::ArrowLocation location = GetArrowLocation(); | 161 BubbleBorder::ArrowLocation location = GetArrowLocation(); |
162 gfx::Point anchor(anchor_view()->bounds().CenterPoint()); | 162 gfx::Point anchor; |
163 // By default, pick the middle of |anchor_view_|'s edge opposite the arrow. | 163 // By default, pick the middle of |anchor_view_|'s edge opposite the arrow. |
164 if (BubbleBorder::is_arrow_on_horizontal(location)) { | 164 if (BubbleBorder::is_arrow_on_horizontal(location)) { |
165 anchor.SetPoint(anchor_view()->width() / 2, | 165 anchor.SetPoint(anchor_view()->width() / 2, |
166 BubbleBorder::is_arrow_on_top(location) ? anchor_view()->height() : 0); | 166 BubbleBorder::is_arrow_on_top(location) ? anchor_view()->height() : 0); |
167 } else if (BubbleBorder::has_arrow(location)) { | 167 } else if (BubbleBorder::has_arrow(location)) { |
168 anchor.SetPoint( | 168 anchor.SetPoint( |
169 BubbleBorder::is_arrow_on_left(location) ? anchor_view()->width() : 0, | 169 BubbleBorder::is_arrow_on_left(location) ? anchor_view()->width() : 0, |
170 anchor_view_->height() / 2); | 170 anchor_view_->height() / 2); |
171 } else { | |
172 anchor = anchor_view()->bounds().CenterPoint(); | |
171 } | 173 } |
172 View::ConvertPointToScreen(anchor_view(), &anchor); | 174 View::ConvertPointToScreen(anchor_view(), &anchor); |
173 return anchor; | 175 return gfx::Rect(anchor, gfx::Size()); |
174 } | 176 } |
175 | 177 |
176 BubbleBorder::ArrowLocation BubbleDelegateView::GetArrowLocation() const { | 178 BubbleBorder::ArrowLocation BubbleDelegateView::GetArrowLocation() const { |
177 return arrow_location_; | 179 return arrow_location_; |
178 } | 180 } |
179 | 181 |
180 SkColor BubbleDelegateView::GetColor() const { | 182 SkColor BubbleDelegateView::GetColor() const { |
181 return color_; | 183 return color_; |
182 } | 184 } |
183 | 185 |
(...skipping 24 matching lines...) Expand all Loading... | |
208 } | 210 } |
209 } | 211 } |
210 | 212 |
211 void BubbleDelegateView::ResetFade() { | 213 void BubbleDelegateView::ResetFade() { |
212 fade_animation_.reset(); | 214 fade_animation_.reset(); |
213 if (border_widget_) | 215 if (border_widget_) |
214 border_widget_->SetOpacity(original_opacity_); | 216 border_widget_->SetOpacity(original_opacity_); |
215 GetWidget()->SetOpacity(original_opacity_); | 217 GetWidget()->SetOpacity(original_opacity_); |
216 } | 218 } |
217 | 219 |
220 void BubbleDelegateView::SetAlignment(BubbleBorder::BubbleAlignment alignment) { | |
221 GetBubbleFrameView()->bubble_border()->set_alignment( | |
222 views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); | |
msw
2011/12/08 00:40:14
Pass along alignment, not this hard-coded value.
sail
2011/12/08 01:41:10
Done.
| |
223 SizeToContents(); | |
224 } | |
225 | |
218 bool BubbleDelegateView::AcceleratorPressed( | 226 bool BubbleDelegateView::AcceleratorPressed( |
219 const ui::Accelerator& accelerator) { | 227 const ui::Accelerator& accelerator) { |
220 if (!close_on_esc() || accelerator.key_code() != ui::VKEY_ESCAPE) | 228 if (!close_on_esc() || accelerator.key_code() != ui::VKEY_ESCAPE) |
221 return false; | 229 return false; |
222 if (fade_animation_.get()) | 230 if (fade_animation_.get()) |
223 fade_animation_->Reset(); | 231 fade_animation_->Reset(); |
224 GetWidget()->Close(); | 232 GetWidget()->Close(); |
225 return true; | 233 return true; |
226 } | 234 } |
227 | 235 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
269 } | 277 } |
270 | 278 |
271 BubbleFrameView* BubbleDelegateView::GetBubbleFrameView() const { | 279 BubbleFrameView* BubbleDelegateView::GetBubbleFrameView() const { |
272 const Widget* widget = border_widget_ ? border_widget_ : GetWidget(); | 280 const Widget* widget = border_widget_ ? border_widget_ : GetWidget(); |
273 return static_cast<BubbleFrameView*>(widget->non_client_view()->frame_view()); | 281 return static_cast<BubbleFrameView*>(widget->non_client_view()->frame_view()); |
274 } | 282 } |
275 | 283 |
276 gfx::Rect BubbleDelegateView::GetBubbleBounds() { | 284 gfx::Rect BubbleDelegateView::GetBubbleBounds() { |
277 // The argument rect has its origin at the bubble's arrow anchor point; | 285 // The argument rect has its origin at the bubble's arrow anchor point; |
278 // its size is the preferred size of the bubble's client view (this view). | 286 // its size is the preferred size of the bubble's client view (this view). |
279 return GetBubbleFrameView()->GetWindowBoundsForClientBounds( | 287 return GetBubbleFrameView()->GetWindowBoundsForAnchorAndClientSize( |
280 gfx::Rect(GetAnchorPoint(), GetPreferredSize())); | 288 GetAnchorRect(), GetPreferredSize()); |
281 } | 289 } |
282 | 290 |
283 #if defined(OS_WIN) && !defined(USE_AURA) | 291 #if defined(OS_WIN) && !defined(USE_AURA) |
284 gfx::Rect BubbleDelegateView::GetBubbleClientBounds() const { | 292 gfx::Rect BubbleDelegateView::GetBubbleClientBounds() const { |
285 gfx::Rect client_bounds(GetBubbleFrameView()->GetBoundsForClientView()); | 293 gfx::Rect client_bounds(GetBubbleFrameView()->GetBoundsForClientView()); |
286 client_bounds.Offset(border_widget_->GetWindowScreenBounds().origin()); | 294 client_bounds.Offset(border_widget_->GetWindowScreenBounds().origin()); |
287 return client_bounds; | 295 return client_bounds; |
288 } | 296 } |
289 #endif | 297 #endif |
290 | 298 |
291 } // namespace views | 299 } // namespace views |
OLD | NEW |