Chromium Code Reviews| 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/accessibility/ax_view_state.h" | 7 #include "ui/accessibility/ax_view_state.h" |
| 8 #include "ui/base/resource/resource_bundle.h" | 8 #include "ui/base/resource/resource_bundle.h" |
| 9 #include "ui/gfx/color_utils.h" | 9 #include "ui/gfx/color_utils.h" |
| 10 #include "ui/gfx/geometry/rect.h" | 10 #include "ui/gfx/geometry/rect.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 43 if (bubble_params.parent) | 43 if (bubble_params.parent) |
| 44 bubble_widget->StackAbove(bubble_params.parent); | 44 bubble_widget->StackAbove(bubble_params.parent); |
| 45 return bubble_widget; | 45 return bubble_widget; |
| 46 } | 46 } |
| 47 | 47 |
| 48 } // namespace | 48 } // namespace |
| 49 | 49 |
| 50 // static | 50 // static |
| 51 const char BubbleDelegateView::kViewClassName[] = "BubbleDelegateView"; | 51 const char BubbleDelegateView::kViewClassName[] = "BubbleDelegateView"; |
| 52 | 52 |
| 53 BubbleDelegateView::BubbleDelegateView() | 53 BubbleDelegateView::BubbleDelegateView() |
|
Devlin
2015/11/18 23:21:27
Grr... silly duplicate constructors. We'll fix yo
| |
| 54 : BubbleDelegateView(nullptr, BubbleBorder::TOP_LEFT) {} | |
| 55 | |
| 56 BubbleDelegateView::BubbleDelegateView(View* anchor_view, | |
| 57 BubbleBorder::Arrow arrow) | |
| 54 : close_on_esc_(true), | 58 : close_on_esc_(true), |
| 55 close_on_deactivate_(true), | 59 close_on_deactivate_(true), |
| 56 anchor_view_storage_id_(ViewStorage::GetInstance()->CreateStorageID()), | 60 anchor_view_storage_id_(ViewStorage::GetInstance()->CreateStorageID()), |
| 57 anchor_widget_(NULL), | |
| 58 arrow_(BubbleBorder::TOP_LEFT), | |
| 59 shadow_(BubbleBorder::SMALL_SHADOW), | |
| 60 color_explicitly_set_(false), | |
| 61 margins_(kDefaultMargin, kDefaultMargin, kDefaultMargin, kDefaultMargin), | |
| 62 accept_events_(true), | |
| 63 border_accepts_events_(true), | |
| 64 adjust_if_offscreen_(true), | |
| 65 parent_window_(NULL) { | |
| 66 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); | |
| 67 UpdateColorsFromTheme(GetNativeTheme()); | |
| 68 } | |
| 69 | |
| 70 BubbleDelegateView::BubbleDelegateView( | |
| 71 View* anchor_view, | |
| 72 BubbleBorder::Arrow arrow) | |
| 73 : close_on_esc_(true), | |
| 74 close_on_deactivate_(true), | |
| 75 anchor_view_storage_id_(ViewStorage::GetInstance()->CreateStorageID()), | |
| 76 anchor_widget_(NULL), | 61 anchor_widget_(NULL), |
| 77 arrow_(arrow), | 62 arrow_(arrow), |
| 78 shadow_(BubbleBorder::SMALL_SHADOW), | 63 shadow_(BubbleBorder::SMALL_SHADOW), |
| 79 color_explicitly_set_(false), | 64 color_explicitly_set_(false), |
| 80 margins_(kDefaultMargin, kDefaultMargin, kDefaultMargin, kDefaultMargin), | 65 margins_(kDefaultMargin, kDefaultMargin, kDefaultMargin, kDefaultMargin), |
| 81 accept_events_(true), | 66 accept_events_(true), |
| 82 border_accepts_events_(true), | 67 border_accepts_events_(true), |
| 83 adjust_if_offscreen_(true), | 68 adjust_if_offscreen_(true), |
| 84 parent_window_(NULL) { | 69 parent_window_(NULL), |
| 85 SetAnchorView(anchor_view); | 70 close_reason_(CloseReason::UNKNOWN) { |
| 71 if (anchor_view) | |
| 72 SetAnchorView(anchor_view); | |
| 86 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); | 73 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); |
| 87 UpdateColorsFromTheme(GetNativeTheme()); | 74 UpdateColorsFromTheme(GetNativeTheme()); |
| 88 } | 75 } |
| 89 | 76 |
| 90 BubbleDelegateView::~BubbleDelegateView() { | 77 BubbleDelegateView::~BubbleDelegateView() { |
| 91 if (GetWidget()) | 78 if (GetWidget()) |
| 92 GetWidget()->RemoveObserver(this); | 79 GetWidget()->RemoveObserver(this); |
| 93 SetLayoutManager(NULL); | 80 SetLayoutManager(NULL); |
| 94 SetAnchorView(NULL); | 81 SetAnchorView(NULL); |
| 95 } | 82 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 144 } | 131 } |
| 145 | 132 |
| 146 void BubbleDelegateView::GetAccessibleState(ui::AXViewState* state) { | 133 void BubbleDelegateView::GetAccessibleState(ui::AXViewState* state) { |
| 147 state->role = ui::AX_ROLE_DIALOG; | 134 state->role = ui::AX_ROLE_DIALOG; |
| 148 } | 135 } |
| 149 | 136 |
| 150 const char* BubbleDelegateView::GetClassName() const { | 137 const char* BubbleDelegateView::GetClassName() const { |
| 151 return kViewClassName; | 138 return kViewClassName; |
| 152 } | 139 } |
| 153 | 140 |
| 141 void BubbleDelegateView::OnWidgetClosing(Widget* widget) { | |
| 142 DCHECK(GetBubbleFrameView()); | |
| 143 if (widget == GetWidget() && close_reason_ == CloseReason::UNKNOWN && | |
| 144 GetBubbleFrameView()->close_button_clicked()) { | |
| 145 close_reason_ = CloseReason::CLOSE_BUTTON; | |
| 146 } | |
| 147 } | |
| 148 | |
| 154 void BubbleDelegateView::OnWidgetDestroying(Widget* widget) { | 149 void BubbleDelegateView::OnWidgetDestroying(Widget* widget) { |
| 155 if (anchor_widget() == widget) | 150 if (anchor_widget() == widget) |
| 156 SetAnchorView(NULL); | 151 SetAnchorView(NULL); |
| 157 } | 152 } |
| 158 | 153 |
| 159 void BubbleDelegateView::OnWidgetVisibilityChanging(Widget* widget, | 154 void BubbleDelegateView::OnWidgetVisibilityChanging(Widget* widget, |
| 160 bool visible) { | 155 bool visible) { |
| 161 #if defined(OS_WIN) | 156 #if defined(OS_WIN) |
| 162 // On Windows we need to handle this before the bubble is visible or hidden. | 157 // On Windows we need to handle this before the bubble is visible or hidden. |
| 163 // Please see the comment on the OnWidgetVisibilityChanging function. On | 158 // Please see the comment on the OnWidgetVisibilityChanging function. On |
| 164 // other platforms it is fine to handle it after the bubble is shown/hidden. | 159 // other platforms it is fine to handle it after the bubble is shown/hidden. |
| 165 HandleVisibilityChanged(widget, visible); | 160 HandleVisibilityChanged(widget, visible); |
| 166 #endif | 161 #endif |
| 167 } | 162 } |
| 168 | 163 |
| 169 void BubbleDelegateView::OnWidgetVisibilityChanged(Widget* widget, | 164 void BubbleDelegateView::OnWidgetVisibilityChanged(Widget* widget, |
| 170 bool visible) { | 165 bool visible) { |
| 171 #if !defined(OS_WIN) | 166 #if !defined(OS_WIN) |
| 172 HandleVisibilityChanged(widget, visible); | 167 HandleVisibilityChanged(widget, visible); |
| 173 #endif | 168 #endif |
| 174 } | 169 } |
| 175 | 170 |
| 176 void BubbleDelegateView::OnWidgetActivationChanged(Widget* widget, | 171 void BubbleDelegateView::OnWidgetActivationChanged(Widget* widget, |
| 177 bool active) { | 172 bool active) { |
| 178 if (close_on_deactivate() && widget == GetWidget() && !active) | 173 if (close_on_deactivate() && widget == GetWidget() && !active) { |
| 174 if (close_reason_ == CloseReason::UNKNOWN) | |
| 175 close_reason_ = CloseReason::DEACTIVATION; | |
| 179 GetWidget()->Close(); | 176 GetWidget()->Close(); |
| 177 } | |
| 180 } | 178 } |
| 181 | 179 |
| 182 void BubbleDelegateView::OnWidgetBoundsChanged(Widget* widget, | 180 void BubbleDelegateView::OnWidgetBoundsChanged(Widget* widget, |
| 183 const gfx::Rect& new_bounds) { | 181 const gfx::Rect& new_bounds) { |
| 184 if (GetBubbleFrameView() && anchor_widget() == widget) | 182 if (GetBubbleFrameView() && anchor_widget() == widget) |
| 185 SizeToContents(); | 183 SizeToContents(); |
| 186 } | 184 } |
| 187 | 185 |
| 188 View* BubbleDelegateView::GetAnchorView() const { | 186 View* BubbleDelegateView::GetAnchorView() const { |
| 189 return ViewStorage::GetInstance()->RetrieveView(anchor_view_storage_id_); | 187 return ViewStorage::GetInstance()->RetrieveView(anchor_view_storage_id_); |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 214 } | 212 } |
| 215 | 213 |
| 216 void BubbleDelegateView::OnAnchorBoundsChanged() { | 214 void BubbleDelegateView::OnAnchorBoundsChanged() { |
| 217 SizeToContents(); | 215 SizeToContents(); |
| 218 } | 216 } |
| 219 | 217 |
| 220 bool BubbleDelegateView::AcceleratorPressed( | 218 bool BubbleDelegateView::AcceleratorPressed( |
| 221 const ui::Accelerator& accelerator) { | 219 const ui::Accelerator& accelerator) { |
| 222 if (!close_on_esc() || accelerator.key_code() != ui::VKEY_ESCAPE) | 220 if (!close_on_esc() || accelerator.key_code() != ui::VKEY_ESCAPE) |
| 223 return false; | 221 return false; |
| 222 close_reason_ = CloseReason::ESCAPE; | |
| 224 GetWidget()->Close(); | 223 GetWidget()->Close(); |
| 225 return true; | 224 return true; |
| 226 } | 225 } |
| 227 | 226 |
| 228 void BubbleDelegateView::OnNativeThemeChanged(const ui::NativeTheme* theme) { | 227 void BubbleDelegateView::OnNativeThemeChanged(const ui::NativeTheme* theme) { |
| 229 UpdateColorsFromTheme(theme); | 228 UpdateColorsFromTheme(theme); |
| 230 } | 229 } |
| 231 | 230 |
| 232 void BubbleDelegateView::Init() {} | 231 void BubbleDelegateView::Init() {} |
| 233 | 232 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 315 // http://crbug.com/474622 for details. | 314 // http://crbug.com/474622 for details. |
| 316 if (widget == GetWidget() && visible) { | 315 if (widget == GetWidget() && visible) { |
| 317 ui::AXViewState state; | 316 ui::AXViewState state; |
| 318 GetAccessibleState(&state); | 317 GetAccessibleState(&state); |
| 319 if (state.role == ui::AX_ROLE_ALERT_DIALOG) | 318 if (state.role == ui::AX_ROLE_ALERT_DIALOG) |
| 320 NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true); | 319 NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true); |
| 321 } | 320 } |
| 322 } | 321 } |
| 323 | 322 |
| 324 } // namespace views | 323 } // namespace views |
| OLD | NEW |