Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/examples/dialog_example.h" | 5 #include "ui/views/examples/dialog_example.h" |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "ui/views/bubble/bubble_dialog_delegate.h" | 9 #include "ui/views/bubble/bubble_dialog_delegate.h" |
| 10 #include "ui/views/controls/button/checkbox.h" | 10 #include "ui/views/controls/button/checkbox.h" |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 238 | 238 |
| 239 void DialogExample::ResizeDialog() { | 239 void DialogExample::ResizeDialog() { |
| 240 DCHECK(last_dialog_); | 240 DCHECK(last_dialog_); |
| 241 Widget* widget = last_dialog_->GetWidget(); | 241 Widget* widget = last_dialog_->GetWidget(); |
| 242 gfx::Rect preferred_bounds(widget->GetRestoredBounds()); | 242 gfx::Rect preferred_bounds(widget->GetRestoredBounds()); |
| 243 preferred_bounds.set_size(widget->non_client_view()->GetPreferredSize()); | 243 preferred_bounds.set_size(widget->non_client_view()->GetPreferredSize()); |
| 244 | 244 |
| 245 // Q: Do we need NonClientFrameView::GetWindowBoundsForClientBounds() here? | 245 // Q: Do we need NonClientFrameView::GetWindowBoundsForClientBounds() here? |
| 246 // A: When DialogCientView properly feeds back sizes, we do not. | 246 // A: When DialogCientView properly feeds back sizes, we do not. |
| 247 widget->SetBoundsConstrained(preferred_bounds); | 247 widget->SetBoundsConstrained(preferred_bounds); |
| 248 | |
| 249 // For user-resizable dialogs, ensure the window manager enforces any new | |
| 250 // minimum size. | |
| 251 widget->OnSizeConstraintsChanged(); | |
| 248 } | 252 } |
| 249 | 253 |
| 250 void DialogExample::ButtonPressed(Button* sender, const ui::Event& event) { | 254 void DialogExample::ButtonPressed(Button* sender, const ui::Event& event) { |
| 251 if (sender == show_) { | 255 if (sender == show_) { |
| 252 if (bubble_->checked()) { | 256 if (bubble_->checked()) { |
| 253 Bubble* bubble = new Bubble(this, sender); | 257 Bubble* bubble = new Bubble(this, sender); |
| 254 last_dialog_ = bubble; | 258 last_dialog_ = bubble; |
| 255 BubbleDialogDelegateView::CreateBubble(bubble); | 259 BubbleDialogDelegateView::CreateBubble(bubble); |
| 256 } else { | 260 } else { |
| 257 Dialog* dialog = new Dialog(this); | 261 Dialog* dialog = new Dialog(this); |
| 258 last_dialog_ = dialog; | 262 last_dialog_ = dialog; |
| 259 dialog->InitDelegate(); | 263 dialog->InitDelegate(); |
| 260 | 264 |
| 261 // constrained_window::CreateBrowserModalDialogViews() allows dialogs to | 265 // constrained_window::CreateBrowserModalDialogViews() allows dialogs to |
| 262 // be created as MODAL_TYPE_WINDOW without specifying a parent. | 266 // be created as MODAL_TYPE_WINDOW without specifying a parent. |
| 263 gfx::NativeView parent = nullptr; | 267 gfx::NativeView parent = nullptr; |
| 264 if (mode_->selected_index() != kFakeModeless) | 268 if (mode_->selected_index() != kFakeModeless) |
| 265 parent = container()->GetWidget()->GetNativeView(); | 269 parent = container()->GetWidget()->GetNativeView(); |
| 266 | 270 |
| 267 DialogDelegate::CreateDialogWidget( | 271 DialogDelegate::CreateDialogWidget( |
| 268 dialog, container()->GetWidget()->GetNativeWindow(), parent); | 272 dialog, container()->GetWidget()->GetNativeWindow(), parent); |
| 273 ResizeDialog(); | |
|
Peter Kasting
2017/02/25 06:04:07
I'm vaguely surprised this is necessary, and doesn
tapted
2017/02/27 10:04:19
Well this was fun to trace :/. It boils down to a
| |
| 269 } | 274 } |
| 270 last_dialog_->GetWidget()->Show(); | 275 last_dialog_->GetWidget()->Show(); |
| 271 return; | 276 return; |
| 272 } | 277 } |
| 273 | 278 |
| 274 if (sender == bubble_) { | 279 if (sender == bubble_) { |
| 275 if (bubble_->checked() && GetModalType() != ui::MODAL_TYPE_CHILD) { | 280 if (bubble_->checked() && GetModalType() != ui::MODAL_TYPE_CHILD) { |
| 276 mode_->SetSelectedIndex(ui::MODAL_TYPE_CHILD); | 281 mode_->SetSelectedIndex(ui::MODAL_TYPE_CHILD); |
| 277 PrintStatus("You nearly always want Child Modal for bubbles."); | 282 PrintStatus("You nearly always want Child Modal for bubbles."); |
| 278 } | 283 } |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 320 #endif | 325 #endif |
| 321 show_->SetEnabled(enable); | 326 show_->SetEnabled(enable); |
| 322 if (!enable && GetModalType() == ui::MODAL_TYPE_CHILD) | 327 if (!enable && GetModalType() == ui::MODAL_TYPE_CHILD) |
| 323 PrintStatus("MODAL_TYPE_CHILD can't be used with non-bubbles."); | 328 PrintStatus("MODAL_TYPE_CHILD can't be used with non-bubbles."); |
| 324 if (!enable && GetModalType() == ui::MODAL_TYPE_SYSTEM) | 329 if (!enable && GetModalType() == ui::MODAL_TYPE_SYSTEM) |
| 325 PrintStatus("MODAL_TYPE_SYSTEM isn't supported on Mac."); | 330 PrintStatus("MODAL_TYPE_SYSTEM isn't supported on Mac."); |
| 326 } | 331 } |
| 327 | 332 |
| 328 } // namespace examples | 333 } // namespace examples |
| 329 } // namespace views | 334 } // namespace views |
| OLD | NEW |