| 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 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 | 201 |
| 202 void BubbleDialogDelegateView::OnAnchorBoundsChanged() { | 202 void BubbleDialogDelegateView::OnAnchorBoundsChanged() { |
| 203 SizeToContents(); | 203 SizeToContents(); |
| 204 } | 204 } |
| 205 | 205 |
| 206 BubbleDialogDelegateView::BubbleDialogDelegateView() | 206 BubbleDialogDelegateView::BubbleDialogDelegateView() |
| 207 : BubbleDialogDelegateView(nullptr, BubbleBorder::TOP_LEFT) {} | 207 : BubbleDialogDelegateView(nullptr, BubbleBorder::TOP_LEFT) {} |
| 208 | 208 |
| 209 BubbleDialogDelegateView::BubbleDialogDelegateView(View* anchor_view, | 209 BubbleDialogDelegateView::BubbleDialogDelegateView(View* anchor_view, |
| 210 BubbleBorder::Arrow arrow) | 210 BubbleBorder::Arrow arrow) |
| 211 : close_on_esc_(true), | 211 : close_on_deactivate_(true), |
| 212 close_on_deactivate_(true), | |
| 213 anchor_view_storage_id_(ViewStorage::GetInstance()->CreateStorageID()), | 212 anchor_view_storage_id_(ViewStorage::GetInstance()->CreateStorageID()), |
| 214 anchor_widget_(NULL), | 213 anchor_widget_(NULL), |
| 215 arrow_(arrow), | 214 arrow_(arrow), |
| 216 shadow_(BubbleBorder::SMALL_SHADOW), | 215 shadow_(BubbleBorder::SMALL_SHADOW), |
| 217 color_explicitly_set_(false), | 216 color_explicitly_set_(false), |
| 218 margins_(kPanelVertMargin, | 217 margins_(kPanelVertMargin, |
| 219 kPanelHorizMargin, | 218 kPanelHorizMargin, |
| 220 kPanelVertMargin, | 219 kPanelVertMargin, |
| 221 kPanelHorizMargin), | 220 kPanelHorizMargin), |
| 222 accept_events_(true), | 221 accept_events_(true), |
| 223 border_accepts_events_(true), | 222 border_accepts_events_(true), |
| 224 adjust_if_offscreen_(true), | 223 adjust_if_offscreen_(true), |
| 225 parent_window_(NULL), | 224 parent_window_(NULL), |
| 226 close_reason_(CloseReason::UNKNOWN) { | 225 close_reason_(CloseReason::UNKNOWN) { |
| 227 if (anchor_view) | 226 if (anchor_view) |
| 228 SetAnchorView(anchor_view); | 227 SetAnchorView(anchor_view); |
| 229 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); | |
| 230 UpdateColorsFromTheme(GetNativeTheme()); | 228 UpdateColorsFromTheme(GetNativeTheme()); |
| 231 } | 229 } |
| 232 | 230 |
| 233 gfx::Rect BubbleDialogDelegateView::GetBubbleBounds() { | 231 gfx::Rect BubbleDialogDelegateView::GetBubbleBounds() { |
| 234 // The argument rect has its origin at the bubble's arrow anchor point; | 232 // The argument rect has its origin at the bubble's arrow anchor point; |
| 235 // its size is the preferred size of the bubble's client view (this view). | 233 // its size is the preferred size of the bubble's client view (this view). |
| 236 bool anchor_minimized = anchor_widget() && anchor_widget()->IsMinimized(); | 234 bool anchor_minimized = anchor_widget() && anchor_widget()->IsMinimized(); |
| 237 return GetBubbleFrameView()->GetUpdatedWindowBounds( | 235 return GetBubbleFrameView()->GetUpdatedWindowBounds( |
| 238 GetAnchorRect(), GetWidget()->client_view()->GetPreferredSize(), | 236 GetAnchorRect(), GetWidget()->client_view()->GetPreferredSize(), |
| 239 adjust_if_offscreen_ && !anchor_minimized); | 237 adjust_if_offscreen_ && !anchor_minimized); |
| 240 } | 238 } |
| 241 | 239 |
| 242 const gfx::FontList& BubbleDialogDelegateView::GetTitleFontList() const { | 240 const gfx::FontList& BubbleDialogDelegateView::GetTitleFontList() const { |
| 243 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 241 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 244 return rb.GetFontList(ui::ResourceBundle::MediumFont); | 242 return rb.GetFontList(ui::ResourceBundle::MediumFont); |
| 245 } | 243 } |
| 246 | 244 |
| 247 bool BubbleDialogDelegateView::AcceleratorPressed( | |
| 248 const ui::Accelerator& accelerator) { | |
| 249 if (!close_on_esc() || accelerator.key_code() != ui::VKEY_ESCAPE) | |
| 250 return false; | |
| 251 close_reason_ = CloseReason::ESCAPE; | |
| 252 GetWidget()->Close(); | |
| 253 return true; | |
| 254 } | |
| 255 | |
| 256 void BubbleDialogDelegateView::OnNativeThemeChanged( | 245 void BubbleDialogDelegateView::OnNativeThemeChanged( |
| 257 const ui::NativeTheme* theme) { | 246 const ui::NativeTheme* theme) { |
| 258 UpdateColorsFromTheme(theme); | 247 UpdateColorsFromTheme(theme); |
| 259 } | 248 } |
| 260 | 249 |
| 261 void BubbleDialogDelegateView::Init() {} | 250 void BubbleDialogDelegateView::Init() {} |
| 262 | 251 |
| 263 void BubbleDialogDelegateView::SetAnchorView(View* anchor_view) { | 252 void BubbleDialogDelegateView::SetAnchorView(View* anchor_view) { |
| 264 // When the anchor view gets set the associated anchor widget might | 253 // When the anchor view gets set the associated anchor widget might |
| 265 // change as well. | 254 // change as well. |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 // http://crbug.com/474622 for details. | 321 // http://crbug.com/474622 for details. |
| 333 if (widget == GetWidget() && visible) { | 322 if (widget == GetWidget() && visible) { |
| 334 ui::AXViewState state; | 323 ui::AXViewState state; |
| 335 GetAccessibleState(&state); | 324 GetAccessibleState(&state); |
| 336 if (state.role == ui::AX_ROLE_ALERT_DIALOG) | 325 if (state.role == ui::AX_ROLE_ALERT_DIALOG) |
| 337 NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true); | 326 NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true); |
| 338 } | 327 } |
| 339 } | 328 } |
| 340 | 329 |
| 341 } // namespace views | 330 } // namespace views |
| OLD | NEW |