| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_dialog_delegate.h" | 5 #include "ui/views/bubble/bubble_dialog_delegate.h" |
| 6 | 6 |
| 7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
| 8 #include "ui/accessibility/ax_view_state.h" | 8 #include "ui/accessibility/ax_view_state.h" |
| 9 #include "ui/base/resource/resource_bundle.h" | 9 #include "ui/base/resource/resource_bundle.h" |
| 10 #include "ui/gfx/color_utils.h" | 10 #include "ui/gfx/color_utils.h" |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 } | 116 } |
| 117 | 117 |
| 118 void BubbleDialogDelegateView::GetAccessibleState(ui::AXViewState* state) { | 118 void BubbleDialogDelegateView::GetAccessibleState(ui::AXViewState* state) { |
| 119 state->role = ui::AX_ROLE_DIALOG; | 119 state->role = ui::AX_ROLE_DIALOG; |
| 120 } | 120 } |
| 121 | 121 |
| 122 const char* BubbleDialogDelegateView::GetClassName() const { | 122 const char* BubbleDialogDelegateView::GetClassName() const { |
| 123 return kViewClassName; | 123 return kViewClassName; |
| 124 } | 124 } |
| 125 | 125 |
| 126 void BubbleDialogDelegateView::OnWidgetClosing(Widget* widget) { | |
| 127 DCHECK(GetBubbleFrameView()); | |
| 128 if (widget == GetWidget() && close_reason_ == CloseReason::UNKNOWN && | |
| 129 GetBubbleFrameView()->close_button_clicked()) { | |
| 130 close_reason_ = CloseReason::CLOSE_BUTTON; | |
| 131 } | |
| 132 } | |
| 133 | |
| 134 void BubbleDialogDelegateView::OnWidgetDestroying(Widget* widget) { | 126 void BubbleDialogDelegateView::OnWidgetDestroying(Widget* widget) { |
| 135 if (anchor_widget() == widget) | 127 if (anchor_widget() == widget) |
| 136 SetAnchorView(NULL); | 128 SetAnchorView(NULL); |
| 137 } | 129 } |
| 138 | 130 |
| 139 void BubbleDialogDelegateView::OnWidgetVisibilityChanging(Widget* widget, | 131 void BubbleDialogDelegateView::OnWidgetVisibilityChanging(Widget* widget, |
| 140 bool visible) { | 132 bool visible) { |
| 141 #if defined(OS_WIN) | 133 #if defined(OS_WIN) |
| 142 // On Windows we need to handle this before the bubble is visible or hidden. | 134 // On Windows we need to handle this before the bubble is visible or hidden. |
| 143 // Please see the comment on the OnWidgetVisibilityChanging function. On | 135 // Please see the comment on the OnWidgetVisibilityChanging function. On |
| 144 // other platforms it is fine to handle it after the bubble is shown/hidden. | 136 // other platforms it is fine to handle it after the bubble is shown/hidden. |
| 145 HandleVisibilityChanged(widget, visible); | 137 HandleVisibilityChanged(widget, visible); |
| 146 #endif | 138 #endif |
| 147 } | 139 } |
| 148 | 140 |
| 149 void BubbleDialogDelegateView::OnWidgetVisibilityChanged(Widget* widget, | 141 void BubbleDialogDelegateView::OnWidgetVisibilityChanged(Widget* widget, |
| 150 bool visible) { | 142 bool visible) { |
| 151 #if !defined(OS_WIN) | 143 #if !defined(OS_WIN) |
| 152 HandleVisibilityChanged(widget, visible); | 144 HandleVisibilityChanged(widget, visible); |
| 153 #endif | 145 #endif |
| 154 } | 146 } |
| 155 | 147 |
| 156 void BubbleDialogDelegateView::OnWidgetActivationChanged(Widget* widget, | 148 void BubbleDialogDelegateView::OnWidgetActivationChanged(Widget* widget, |
| 157 bool active) { | 149 bool active) { |
| 158 if (close_on_deactivate() && widget == GetWidget() && !active) { | 150 if (close_on_deactivate() && widget == GetWidget() && !active) |
| 159 if (close_reason_ == CloseReason::UNKNOWN) | |
| 160 close_reason_ = CloseReason::DEACTIVATION; | |
| 161 GetWidget()->Close(); | 151 GetWidget()->Close(); |
| 162 } | |
| 163 } | 152 } |
| 164 | 153 |
| 165 void BubbleDialogDelegateView::OnWidgetBoundsChanged( | 154 void BubbleDialogDelegateView::OnWidgetBoundsChanged( |
| 166 Widget* widget, | 155 Widget* widget, |
| 167 const gfx::Rect& new_bounds) { | 156 const gfx::Rect& new_bounds) { |
| 168 if (GetBubbleFrameView() && anchor_widget() == widget) | 157 if (GetBubbleFrameView() && anchor_widget() == widget) |
| 169 SizeToContents(); | 158 SizeToContents(); |
| 170 } | 159 } |
| 171 | 160 |
| 172 View* BubbleDialogDelegateView::GetAnchorView() const { | 161 View* BubbleDialogDelegateView::GetAnchorView() const { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 arrow_(arrow), | 207 arrow_(arrow), |
| 219 shadow_(BubbleBorder::SMALL_SHADOW), | 208 shadow_(BubbleBorder::SMALL_SHADOW), |
| 220 color_explicitly_set_(false), | 209 color_explicitly_set_(false), |
| 221 margins_(kPanelVertMargin, | 210 margins_(kPanelVertMargin, |
| 222 kPanelHorizMargin, | 211 kPanelHorizMargin, |
| 223 kPanelVertMargin, | 212 kPanelVertMargin, |
| 224 kPanelHorizMargin), | 213 kPanelHorizMargin), |
| 225 accept_events_(true), | 214 accept_events_(true), |
| 226 border_accepts_events_(true), | 215 border_accepts_events_(true), |
| 227 adjust_if_offscreen_(true), | 216 adjust_if_offscreen_(true), |
| 228 parent_window_(NULL), | 217 parent_window_(NULL) { |
| 229 close_reason_(CloseReason::UNKNOWN) { | |
| 230 if (anchor_view) | 218 if (anchor_view) |
| 231 SetAnchorView(anchor_view); | 219 SetAnchorView(anchor_view); |
| 232 UpdateColorsFromTheme(GetNativeTheme()); | 220 UpdateColorsFromTheme(GetNativeTheme()); |
| 233 } | 221 } |
| 234 | 222 |
| 235 gfx::Rect BubbleDialogDelegateView::GetBubbleBounds() { | 223 gfx::Rect BubbleDialogDelegateView::GetBubbleBounds() { |
| 236 // The argument rect has its origin at the bubble's arrow anchor point; | 224 // The argument rect has its origin at the bubble's arrow anchor point; |
| 237 // its size is the preferred size of the bubble's client view (this view). | 225 // its size is the preferred size of the bubble's client view (this view). |
| 238 bool anchor_minimized = anchor_widget() && anchor_widget()->IsMinimized(); | 226 bool anchor_minimized = anchor_widget() && anchor_widget()->IsMinimized(); |
| 239 return GetBubbleFrameView()->GetUpdatedWindowBounds( | 227 return GetBubbleFrameView()->GetUpdatedWindowBounds( |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 // http://crbug.com/474622 for details. | 310 // http://crbug.com/474622 for details. |
| 323 if (widget == GetWidget() && visible) { | 311 if (widget == GetWidget() && visible) { |
| 324 ui::AXViewState state; | 312 ui::AXViewState state; |
| 325 GetAccessibleState(&state); | 313 GetAccessibleState(&state); |
| 326 if (state.role == ui::AX_ROLE_ALERT_DIALOG) | 314 if (state.role == ui::AX_ROLE_ALERT_DIALOG) |
| 327 NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true); | 315 NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true); |
| 328 } | 316 } |
| 329 } | 317 } |
| 330 | 318 |
| 331 } // namespace views | 319 } // namespace views |
| OLD | NEW |