| 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/views/bubble/bubble_frame_view.h" | 9 #include "ui/views/bubble/bubble_frame_view.h" |
| 10 #include "ui/views/widget/widget.h" | 10 #include "ui/views/widget/widget.h" |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 const SkColor BubbleDelegateView::kBackgroundColor = SK_ColorWHITE; | 104 const SkColor BubbleDelegateView::kBackgroundColor = SK_ColorWHITE; |
| 105 #endif | 105 #endif |
| 106 | 106 |
| 107 BubbleDelegateView::BubbleDelegateView() | 107 BubbleDelegateView::BubbleDelegateView() |
| 108 : close_on_esc_(true), | 108 : close_on_esc_(true), |
| 109 close_on_deactivate_(true), | 109 close_on_deactivate_(true), |
| 110 anchor_view_(NULL), | 110 anchor_view_(NULL), |
| 111 anchor_widget_(NULL), | 111 anchor_widget_(NULL), |
| 112 move_with_anchor_(false), | 112 move_with_anchor_(false), |
| 113 arrow_location_(BubbleBorder::TOP_LEFT), | 113 arrow_location_(BubbleBorder::TOP_LEFT), |
| 114 shadow_(BubbleBorder::NO_SHADOW), |
| 114 color_(kBackgroundColor), | 115 color_(kBackgroundColor), |
| 115 margins_(kDefaultMargin, kDefaultMargin, kDefaultMargin, kDefaultMargin), | 116 margins_(kDefaultMargin, kDefaultMargin, kDefaultMargin, kDefaultMargin), |
| 116 original_opacity_(255), | 117 original_opacity_(255), |
| 117 border_widget_(NULL), | 118 border_widget_(NULL), |
| 118 use_focusless_(false), | 119 use_focusless_(false), |
| 119 accept_events_(true), | 120 accept_events_(true), |
| 120 try_mirroring_arrow_(true), | 121 adjust_if_offscreen_(true), |
| 121 parent_window_(NULL) { | 122 parent_window_(NULL) { |
| 122 set_background(Background::CreateSolidBackground(color_)); | 123 set_background(Background::CreateSolidBackground(color_)); |
| 123 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); | 124 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); |
| 124 } | 125 } |
| 125 | 126 |
| 126 BubbleDelegateView::BubbleDelegateView( | 127 BubbleDelegateView::BubbleDelegateView( |
| 127 View* anchor_view, | 128 View* anchor_view, |
| 128 BubbleBorder::ArrowLocation arrow_location) | 129 BubbleBorder::ArrowLocation arrow_location) |
| 129 : close_on_esc_(true), | 130 : close_on_esc_(true), |
| 130 close_on_deactivate_(true), | 131 close_on_deactivate_(true), |
| 131 anchor_view_(anchor_view), | 132 anchor_view_(anchor_view), |
| 132 anchor_widget_(NULL), | 133 anchor_widget_(NULL), |
| 133 move_with_anchor_(false), | 134 move_with_anchor_(false), |
| 134 arrow_location_(arrow_location), | 135 arrow_location_(arrow_location), |
| 136 shadow_(BubbleBorder::NO_SHADOW), |
| 135 color_(kBackgroundColor), | 137 color_(kBackgroundColor), |
| 136 margins_(kDefaultMargin, kDefaultMargin, kDefaultMargin, kDefaultMargin), | 138 margins_(kDefaultMargin, kDefaultMargin, kDefaultMargin, kDefaultMargin), |
| 137 original_opacity_(255), | 139 original_opacity_(255), |
| 138 border_widget_(NULL), | 140 border_widget_(NULL), |
| 139 use_focusless_(false), | 141 use_focusless_(false), |
| 140 accept_events_(true), | 142 accept_events_(true), |
| 141 try_mirroring_arrow_(true), | 143 adjust_if_offscreen_(true), |
| 142 parent_window_(NULL) { | 144 parent_window_(NULL) { |
| 143 set_background(Background::CreateSolidBackground(color_)); | 145 set_background(Background::CreateSolidBackground(color_)); |
| 144 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); | 146 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); |
| 145 } | 147 } |
| 146 | 148 |
| 147 BubbleDelegateView::~BubbleDelegateView() { | 149 BubbleDelegateView::~BubbleDelegateView() { |
| 148 if (anchor_widget() != NULL) | 150 if (anchor_widget() != NULL) |
| 149 anchor_widget()->RemoveObserver(this); | 151 anchor_widget()->RemoveObserver(this); |
| 150 anchor_widget_ = NULL; | 152 anchor_widget_ = NULL; |
| 151 anchor_view_ = NULL; | 153 anchor_view_ = NULL; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 | 189 |
| 188 View* BubbleDelegateView::GetContentsView() { | 190 View* BubbleDelegateView::GetContentsView() { |
| 189 return this; | 191 return this; |
| 190 } | 192 } |
| 191 | 193 |
| 192 NonClientFrameView* BubbleDelegateView::CreateNonClientFrameView( | 194 NonClientFrameView* BubbleDelegateView::CreateNonClientFrameView( |
| 193 Widget* widget) { | 195 Widget* widget) { |
| 194 BubbleBorder::ArrowLocation arrow_loc = arrow_location(); | 196 BubbleBorder::ArrowLocation arrow_loc = arrow_location(); |
| 195 if (base::i18n::IsRTL()) | 197 if (base::i18n::IsRTL()) |
| 196 arrow_loc = BubbleBorder::horizontal_mirror(arrow_loc); | 198 arrow_loc = BubbleBorder::horizontal_mirror(arrow_loc); |
| 197 // TODO(alicet): Expose the shadow option in BorderContentsView when we make | 199 BubbleBorder* border = new BubbleBorder(arrow_loc, shadow_); |
| 198 // the fullscreen exit bubble use the new bubble code. | |
| 199 BubbleBorder* border = new BubbleBorder(arrow_loc, BubbleBorder::NO_SHADOW); | |
| 200 border->set_background_color(color()); | 200 border->set_background_color(color()); |
| 201 BubbleFrameView* frame_view = new BubbleFrameView(margins(), border); | 201 BubbleFrameView* frame_view = new BubbleFrameView(margins(), border); |
| 202 frame_view->set_background(new BubbleBackground(border)); | 202 frame_view->set_background(new BubbleBackground(border)); |
| 203 return frame_view; | 203 return frame_view; |
| 204 } | 204 } |
| 205 | 205 |
| 206 void BubbleDelegateView::OnWidgetClosing(Widget* widget) { | 206 void BubbleDelegateView::OnWidgetClosing(Widget* widget) { |
| 207 if (anchor_widget() == widget) { | 207 if (anchor_widget() == widget) { |
| 208 anchor_view_ = NULL; | 208 anchor_view_ = NULL; |
| 209 anchor_widget_ = NULL; | 209 anchor_widget_ = NULL; |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 BubbleFrameView* BubbleDelegateView::GetBubbleFrameView() const { | 343 BubbleFrameView* BubbleDelegateView::GetBubbleFrameView() const { |
| 344 const Widget* widget = border_widget_ ? border_widget_ : GetWidget(); | 344 const Widget* widget = border_widget_ ? border_widget_ : GetWidget(); |
| 345 const NonClientView* view = widget ? widget->non_client_view() : NULL; | 345 const NonClientView* view = widget ? widget->non_client_view() : NULL; |
| 346 return view ? static_cast<BubbleFrameView*>(view->frame_view()) : NULL; | 346 return view ? static_cast<BubbleFrameView*>(view->frame_view()) : NULL; |
| 347 } | 347 } |
| 348 | 348 |
| 349 gfx::Rect BubbleDelegateView::GetBubbleBounds() { | 349 gfx::Rect BubbleDelegateView::GetBubbleBounds() { |
| 350 // The argument rect has its origin at the bubble's arrow anchor point; | 350 // The argument rect has its origin at the bubble's arrow anchor point; |
| 351 // its size is the preferred size of the bubble's client view (this view). | 351 // its size is the preferred size of the bubble's client view (this view). |
| 352 return GetBubbleFrameView()->GetUpdatedWindowBounds(GetAnchorRect(), | 352 return GetBubbleFrameView()->GetUpdatedWindowBounds(GetAnchorRect(), |
| 353 GetPreferredSize(), try_mirroring_arrow_); | 353 GetPreferredSize(), adjust_if_offscreen_); |
| 354 } | 354 } |
| 355 | 355 |
| 356 #if defined(OS_WIN) && !defined(USE_AURA) | 356 #if defined(OS_WIN) && !defined(USE_AURA) |
| 357 gfx::Rect BubbleDelegateView::GetBubbleClientBounds() const { | 357 gfx::Rect BubbleDelegateView::GetBubbleClientBounds() const { |
| 358 gfx::Rect client_bounds(GetBubbleFrameView()->GetBoundsForClientView()); | 358 gfx::Rect client_bounds(GetBubbleFrameView()->GetBoundsForClientView()); |
| 359 client_bounds.Offset(border_widget_->GetWindowBoundsInScreen().origin()); | 359 client_bounds.Offset(border_widget_->GetWindowBoundsInScreen().origin()); |
| 360 return client_bounds; | 360 return client_bounds; |
| 361 } | 361 } |
| 362 #endif | 362 #endif |
| 363 | 363 |
| 364 } // namespace views | 364 } // namespace views |
| OLD | NEW |