| 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 border_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 68 border_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 69 border_widget->Init(border_params); | 69 border_widget->Init(border_params); |
| 70 return border_widget; | 70 return border_widget; |
| 71 } | 71 } |
| 72 #endif | 72 #endif |
| 73 | 73 |
| 74 } // namespace | 74 } // namespace |
| 75 | 75 |
| 76 BubbleDelegateView::BubbleDelegateView() | 76 BubbleDelegateView::BubbleDelegateView() |
| 77 : close_on_esc_(true), | 77 : close_on_esc_(true), |
| 78 close_on_deactivate_(true), |
| 78 allow_bubble_offscreen_(true), | 79 allow_bubble_offscreen_(true), |
| 79 arrow_location_(BubbleBorder::TOP_LEFT), | 80 arrow_location_(BubbleBorder::TOP_LEFT), |
| 80 color_(SK_ColorWHITE), | 81 color_(SK_ColorWHITE), |
| 81 border_widget_(NULL) { | 82 border_widget_(NULL) { |
| 82 set_background(views::Background::CreateSolidBackground(color_)); | 83 set_background(views::Background::CreateSolidBackground(color_)); |
| 83 AddAccelerator(Accelerator(ui::VKEY_ESCAPE, 0)); | 84 AddAccelerator(Accelerator(ui::VKEY_ESCAPE, 0)); |
| 84 } | 85 } |
| 85 | 86 |
| 86 BubbleDelegateView::BubbleDelegateView( | 87 BubbleDelegateView::BubbleDelegateView( |
| 87 const gfx::Point& anchor_point, | 88 const gfx::Point& anchor_point, |
| 88 BubbleBorder::ArrowLocation arrow_location, | 89 BubbleBorder::ArrowLocation arrow_location, |
| 89 const SkColor& color) | 90 const SkColor& color) |
| 90 : close_on_esc_(true), | 91 : close_on_esc_(true), |
| 92 close_on_deactivate_(true), |
| 91 allow_bubble_offscreen_(true), | 93 allow_bubble_offscreen_(true), |
| 92 anchor_point_(anchor_point), | 94 anchor_point_(anchor_point), |
| 93 arrow_location_(arrow_location), | 95 arrow_location_(arrow_location), |
| 94 color_(color), | 96 color_(color), |
| 95 original_opacity_(255), | 97 original_opacity_(255), |
| 96 border_widget_(NULL) { | 98 border_widget_(NULL) { |
| 97 set_background(views::Background::CreateSolidBackground(color_)); | 99 set_background(views::Background::CreateSolidBackground(color_)); |
| 98 AddAccelerator(Accelerator(ui::VKEY_ESCAPE, 0)); | 100 AddAccelerator(Accelerator(ui::VKEY_ESCAPE, 0)); |
| 99 } | 101 } |
| 100 | 102 |
| 101 BubbleDelegateView::~BubbleDelegateView() { | 103 BubbleDelegateView::~BubbleDelegateView() { |
| 102 if (border_widget_) | 104 if (border_widget_) |
| 103 border_widget_->Close(); | 105 border_widget_->Close(); |
| 104 } | 106 } |
| 105 | 107 |
| 106 // static | 108 // static |
| 107 Widget* BubbleDelegateView::CreateBubble(BubbleDelegateView* bubble_delegate, | 109 Widget* BubbleDelegateView::CreateBubble(BubbleDelegateView* bubble_delegate, |
| 108 Widget* parent_widget) { | 110 Widget* parent_widget) { |
| 109 bubble_delegate->Init(); | 111 bubble_delegate->Init(); |
| 110 Widget* bubble_widget = CreateBubbleWidget(bubble_delegate, parent_widget); | 112 Widget* bubble_widget = CreateBubbleWidget(bubble_delegate, parent_widget); |
| 111 | 113 |
| 112 #if defined(OS_WIN) && !defined(USE_AURA) | 114 #if defined(OS_WIN) && !defined(USE_AURA) |
| 113 bubble_delegate->InitializeBorderWidget(parent_widget); | 115 bubble_delegate->InitializeBorderWidget(parent_widget); |
| 114 bubble_widget->SetContentsView(bubble_delegate->GetContentsView()); | 116 bubble_widget->SetContentsView(bubble_delegate->GetContentsView()); |
| 115 bubble_widget->SetBounds(bubble_delegate->GetBubbleClientBounds()); | 117 bubble_widget->SetBounds(bubble_delegate->GetBubbleClientBounds()); |
| 116 #else | 118 #else |
| 117 bubble_widget->SetBounds(bubble_delegate->GetBubbleBounds()); | 119 bubble_widget->SetBounds(bubble_delegate->GetBubbleBounds()); |
| 118 #endif | 120 #endif |
| 119 | 121 |
| 122 bubble_widget->AddObserver(bubble_delegate); |
| 123 if (parent_widget && parent_widget->GetTopLevelWidget()) |
| 124 parent_widget->GetTopLevelWidget()->DisableInactiveRendering(); |
| 120 return bubble_widget; | 125 return bubble_widget; |
| 121 } | 126 } |
| 122 | 127 |
| 123 View* BubbleDelegateView::GetInitiallyFocusedView() { | 128 View* BubbleDelegateView::GetInitiallyFocusedView() { |
| 124 return this; | 129 return this; |
| 125 } | 130 } |
| 126 | 131 |
| 127 View* BubbleDelegateView::GetContentsView() { | 132 View* BubbleDelegateView::GetContentsView() { |
| 128 return this; | 133 return this; |
| 129 } | 134 } |
| 130 | 135 |
| 131 NonClientFrameView* BubbleDelegateView::CreateNonClientFrameView() { | 136 NonClientFrameView* BubbleDelegateView::CreateNonClientFrameView() { |
| 132 return new BubbleFrameView(GetArrowLocation(), | 137 return new BubbleFrameView(GetArrowLocation(), |
| 133 GetPreferredSize(), | 138 GetPreferredSize(), |
| 134 GetColor(), | 139 GetColor(), |
| 135 allow_bubble_offscreen_); | 140 allow_bubble_offscreen_); |
| 136 } | 141 } |
| 137 | 142 |
| 143 void BubbleDelegateView::OnWidgetActivationChanged(Widget* widget, |
| 144 bool active) { |
| 145 if (close_on_deactivate() && widget == GetWidget() && !active) { |
| 146 GetWidget()->RemoveObserver(this); |
| 147 GetWidget()->Close(); |
| 148 } |
| 149 } |
| 150 |
| 138 gfx::Point BubbleDelegateView::GetAnchorPoint() { | 151 gfx::Point BubbleDelegateView::GetAnchorPoint() { |
| 139 return anchor_point_; | 152 return anchor_point_; |
| 140 } | 153 } |
| 141 | 154 |
| 142 BubbleBorder::ArrowLocation BubbleDelegateView::GetArrowLocation() const { | 155 BubbleBorder::ArrowLocation BubbleDelegateView::GetArrowLocation() const { |
| 143 return arrow_location_; | 156 return arrow_location_; |
| 144 } | 157 } |
| 145 | 158 |
| 146 SkColor BubbleDelegateView::GetColor() const { | 159 SkColor BubbleDelegateView::GetColor() const { |
| 147 return color_; | 160 return color_; |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 } | 251 } |
| 239 | 252 |
| 240 gfx::Rect BubbleDelegateView::GetBubbleClientBounds() const { | 253 gfx::Rect BubbleDelegateView::GetBubbleClientBounds() const { |
| 241 gfx::Rect client_bounds(GetBubbleFrameView()->GetBoundsForClientView()); | 254 gfx::Rect client_bounds(GetBubbleFrameView()->GetBoundsForClientView()); |
| 242 client_bounds.Offset(border_widget_->GetWindowScreenBounds().origin()); | 255 client_bounds.Offset(border_widget_->GetWindowScreenBounds().origin()); |
| 243 return client_bounds; | 256 return client_bounds; |
| 244 } | 257 } |
| 245 #endif | 258 #endif |
| 246 | 259 |
| 247 } // namespace views | 260 } // namespace views |
| OLD | NEW |