Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: ui/views/window/dialog_delegate.cc

Issue 2375843003: views: add Harmony dialog width support (Closed)
Patch Set: round 1 Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/views/window/dialog_delegate.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/window/dialog_delegate.h" 5 #include "ui/views/window/dialog_delegate.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
11 #include "ui/accessibility/ax_view_state.h" 11 #include "ui/accessibility/ax_view_state.h"
12 #include "ui/base/l10n/l10n_util.h" 12 #include "ui/base/l10n/l10n_util.h"
13 #include "ui/base/material_design/material_design_controller.h"
13 #include "ui/gfx/color_palette.h" 14 #include "ui/gfx/color_palette.h"
14 #include "ui/strings/grit/ui_strings.h" 15 #include "ui/strings/grit/ui_strings.h"
15 #include "ui/views/bubble/bubble_border.h" 16 #include "ui/views/bubble/bubble_border.h"
16 #include "ui/views/bubble/bubble_frame_view.h" 17 #include "ui/views/bubble/bubble_frame_view.h"
17 #include "ui/views/controls/button/label_button.h" 18 #include "ui/views/controls/button/label_button.h"
18 #include "ui/views/layout/layout_constants.h" 19 #include "ui/views/layout/layout_constants.h"
19 #include "ui/views/style/platform_style.h" 20 #include "ui/views/style/platform_style.h"
20 #include "ui/views/widget/widget.h" 21 #include "ui/views/widget/widget.h"
21 #include "ui/views/widget/widget_observer.h" 22 #include "ui/views/widget/widget_observer.h"
22 #include "ui/views/window/dialog_client_view.h" 23 #include "ui/views/window/dialog_client_view.h"
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 button->SetText(GetDialogButtonLabel(type)); 122 button->SetText(GetDialogButtonLabel(type));
122 button->SetEnabled(IsDialogButtonEnabled(type)); 123 button->SetEnabled(IsDialogButtonEnabled(type));
123 bool is_default = type == GetDefaultDialogButton(); 124 bool is_default = type == GetDefaultDialogButton();
124 if (!PlatformStyle::kDialogDefaultButtonCanBeCancel && 125 if (!PlatformStyle::kDialogDefaultButtonCanBeCancel &&
125 type == ui::DIALOG_BUTTON_CANCEL) { 126 type == ui::DIALOG_BUTTON_CANCEL) {
126 is_default = false; 127 is_default = false;
127 } 128 }
128 button->SetIsDefault(is_default); 129 button->SetIsDefault(is_default);
129 } 130 }
130 131
132 DialogDelegate::DialogWidth DialogDelegate::GetDialogWidth() const {
133 return DIALOG_WIDTH_DEFAULT;
134 }
135
131 int DialogDelegate::GetDialogButtons() const { 136 int DialogDelegate::GetDialogButtons() const {
132 return ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL; 137 return ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL;
133 } 138 }
134 139
135 int DialogDelegate::GetDefaultDialogButton() const { 140 int DialogDelegate::GetDefaultDialogButton() const {
136 if (GetDialogButtons() & ui::DIALOG_BUTTON_OK) 141 if (GetDialogButtons() & ui::DIALOG_BUTTON_OK)
137 return ui::DIALOG_BUTTON_OK; 142 return ui::DIALOG_BUTTON_OK;
138 if (GetDialogButtons() & ui::DIALOG_BUTTON_CANCEL) 143 if (GetDialogButtons() & ui::DIALOG_BUTTON_CANCEL)
139 return ui::DIALOG_BUTTON_CANCEL; 144 return ui::DIALOG_BUTTON_CANCEL;
140 return ui::DIALOG_BUTTON_NONE; 145 return ui::DIALOG_BUTTON_NONE;
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 state->name = GetWindowTitle(); 266 state->name = GetWindowTitle();
262 state->role = ui::AX_ROLE_DIALOG; 267 state->role = ui::AX_ROLE_DIALOG;
263 } 268 }
264 269
265 void DialogDelegateView::ViewHierarchyChanged( 270 void DialogDelegateView::ViewHierarchyChanged(
266 const ViewHierarchyChangedDetails& details) { 271 const ViewHierarchyChangedDetails& details) {
267 if (details.is_add && details.child == this && GetWidget()) 272 if (details.is_add && details.child == this && GetWidget())
268 NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true); 273 NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true);
269 } 274 }
270 275
276 gfx::Size DialogDelegateView::GetPreferredSize() const {
277 DialogDelegate::DialogWidth width = DialogDelegate::DIALOG_WIDTH_DEFAULT;
Evan Stade 2016/09/28 21:12:38 maybe cleaner (especially when it comes time to re
Elly Fong-Jones 2016/10/03 13:34:44 Done.
278 int width_px = 0;
279 if (ui::MaterialDesignController::IsSecondaryUiMaterial())
280 width = GetDialogWidth();
281 switch (width) {
282 // TODO(ellyjones): eventually remove support for DIALOG_WIDTH_DEFAULT once
283 // all DialogDelegate implementations have GetDefaultDialogWidth().
284 case DialogDelegate::DIALOG_WIDTH_DEFAULT:
Evan Stade 2016/09/28 21:12:38 nit: maybe DIALOG_WIDTH_UNSPECIFIED?
Elly Fong-Jones 2016/10/03 13:34:44 Done.
285 return View::GetPreferredSize();
286 break;
287 case DialogDelegate::DIALOG_WIDTH_SMALL:
Evan Stade 2016/09/28 21:12:38 perhaps the enum should be: enum WidthFactor {
Elly Fong-Jones 2016/10/03 13:34:44 Oh, that's really clever! Done.
288 width_px = 320;
289 break;
290 case DialogDelegate::DIALOG_WIDTH_MEDIUM:
Evan Stade 2016/09/28 21:12:38 nit: don't need to qualify these constants with Di
Elly Fong-Jones 2016/10/03 13:34:44 Done.
291 width_px = 448;
292 break;
293 case DialogDelegate::DIALOG_WIDTH_LARGE:
294 width_px = 512;
295 break;
296 }
297 return gfx::Size(width_px, GetHeightForWidth(width_px));
298 }
299
271 } // namespace views 300 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/window/dialog_delegate.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698