| 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 void BubbleDelegateView::Show() { | 182 void BubbleDelegateView::Show() { |
| 181 if (border_widget_) | 183 if (border_widget_) |
| 182 border_widget_->Show(); | 184 border_widget_->Show(); |
| 183 GetWidget()->Show(); | 185 GetWidget()->Show(); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 204 } | 206 } |
| 205 } | 207 } |
| 206 | 208 |
| 207 void BubbleDelegateView::ResetFade() { | 209 void BubbleDelegateView::ResetFade() { |
| 208 fade_animation_.reset(); | 210 fade_animation_.reset(); |
| 209 if (border_widget_) | 211 if (border_widget_) |
| 210 border_widget_->SetOpacity(original_opacity_); | 212 border_widget_->SetOpacity(original_opacity_); |
| 211 GetWidget()->SetOpacity(original_opacity_); | 213 GetWidget()->SetOpacity(original_opacity_); |
| 212 } | 214 } |
| 213 | 215 |
| 216 void BubbleDelegateView::SetAlignment(BubbleBorder::BubbleAlignment alignment) { |
| 217 GetBubbleFrameView()->bubble_border()->set_alignment(alignment); |
| 218 SizeToContents(); |
| 219 } |
| 220 |
| 214 bool BubbleDelegateView::AcceleratorPressed( | 221 bool BubbleDelegateView::AcceleratorPressed( |
| 215 const ui::Accelerator& accelerator) { | 222 const ui::Accelerator& accelerator) { |
| 216 if (!close_on_esc() || accelerator.key_code() != ui::VKEY_ESCAPE) | 223 if (!close_on_esc() || accelerator.key_code() != ui::VKEY_ESCAPE) |
| 217 return false; | 224 return false; |
| 218 if (fade_animation_.get()) | 225 if (fade_animation_.get()) |
| 219 fade_animation_->Reset(); | 226 fade_animation_->Reset(); |
| 220 GetWidget()->Close(); | 227 GetWidget()->Close(); |
| 221 return true; | 228 return true; |
| 222 } | 229 } |
| 223 | 230 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 } | 272 } |
| 266 | 273 |
| 267 BubbleFrameView* BubbleDelegateView::GetBubbleFrameView() const { | 274 BubbleFrameView* BubbleDelegateView::GetBubbleFrameView() const { |
| 268 const Widget* widget = border_widget_ ? border_widget_ : GetWidget(); | 275 const Widget* widget = border_widget_ ? border_widget_ : GetWidget(); |
| 269 return static_cast<BubbleFrameView*>(widget->non_client_view()->frame_view()); | 276 return static_cast<BubbleFrameView*>(widget->non_client_view()->frame_view()); |
| 270 } | 277 } |
| 271 | 278 |
| 272 gfx::Rect BubbleDelegateView::GetBubbleBounds() { | 279 gfx::Rect BubbleDelegateView::GetBubbleBounds() { |
| 273 // The argument rect has its origin at the bubble's arrow anchor point; | 280 // The argument rect has its origin at the bubble's arrow anchor point; |
| 274 // its size is the preferred size of the bubble's client view (this view). | 281 // its size is the preferred size of the bubble's client view (this view). |
| 275 return GetBubbleFrameView()->GetWindowBoundsForClientBounds( | 282 return GetBubbleFrameView()->GetWindowBoundsForAnchorAndClientSize( |
| 276 gfx::Rect(GetAnchorPoint(), GetPreferredSize())); | 283 GetAnchorRect(), GetPreferredSize()); |
| 277 } | 284 } |
| 278 | 285 |
| 279 #if defined(OS_WIN) && !defined(USE_AURA) | 286 #if defined(OS_WIN) && !defined(USE_AURA) |
| 280 gfx::Rect BubbleDelegateView::GetBubbleClientBounds() const { | 287 gfx::Rect BubbleDelegateView::GetBubbleClientBounds() const { |
| 281 gfx::Rect client_bounds(GetBubbleFrameView()->GetBoundsForClientView()); | 288 gfx::Rect client_bounds(GetBubbleFrameView()->GetBoundsForClientView()); |
| 282 client_bounds.Offset(border_widget_->GetWindowScreenBounds().origin()); | 289 client_bounds.Offset(border_widget_->GetWindowScreenBounds().origin()); |
| 283 return client_bounds; | 290 return client_bounds; |
| 284 } | 291 } |
| 285 #endif | 292 #endif |
| 286 | 293 |
| 287 } // namespace views | 294 } // namespace views |
| OLD | NEW |