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

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

Issue 2200193004: Support multiple lines for status text on Chooser UI (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixed the button height Created 4 years, 4 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_client_view.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_client_view.h" 5 #include "ui/views/window/dialog_client_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "build/build_config.h" 9 #include "build/build_config.h"
10 #include "ui/base/material_design/material_design_controller.h" 10 #include "ui/base/material_design/material_design_controller.h"
11 #include "ui/events/keycodes/keyboard_codes.h" 11 #include "ui/events/keycodes/keyboard_codes.h"
12 #include "ui/views/background.h" 12 #include "ui/views/background.h"
13 #include "ui/views/controls/button/blue_button.h" 13 #include "ui/views/controls/button/blue_button.h"
14 #include "ui/views/controls/button/custom_button.h"
14 #include "ui/views/controls/button/label_button.h" 15 #include "ui/views/controls/button/label_button.h"
15 #include "ui/views/controls/button/md_text_button.h" 16 #include "ui/views/controls/button/md_text_button.h"
16 #include "ui/views/layout/layout_constants.h" 17 #include "ui/views/layout/layout_constants.h"
17 #include "ui/views/widget/widget.h" 18 #include "ui/views/widget/widget.h"
18 #include "ui/views/window/dialog_delegate.h" 19 #include "ui/views/window/dialog_delegate.h"
19 20
20 namespace views { 21 namespace views {
21 22
22 namespace { 23 namespace {
23 24
24 // The group used by the buttons. This name is chosen voluntarily big not to 25 // The group used by the buttons. This name is chosen voluntarily big not to
25 // conflict with other groups that could be in the dialog content. 26 // conflict with other groups that could be in the dialog content.
26 const int kButtonGroup = 6666; 27 const int kButtonGroup = 6666;
27 28
28 #if defined(OS_WIN) || defined(OS_CHROMEOS) 29 #if defined(OS_WIN) || defined(OS_CHROMEOS)
29 const bool kIsOkButtonOnLeftSide = true; 30 const bool kIsOkButtonOnLeftSide = true;
30 #else 31 #else
31 const bool kIsOkButtonOnLeftSide = false; 32 const bool kIsOkButtonOnLeftSide = false;
32 #endif 33 #endif
33 34
34 // Returns true if the given view should be shown (i.e. exists and is 35 // Returns true if the given view should be shown (i.e. exists and is
35 // visible). 36 // visible).
36 bool ShouldShow(View* view) { 37 bool ShouldShow(View* view) {
37 return view && view->visible(); 38 return view && view->visible();
38 } 39 }
39 40
40 // Do the layout for a button. 41 // Do the layout for a button.
41 void LayoutButton(LabelButton* button, gfx::Rect* row_bounds) { 42 void LayoutButton(LabelButton* button,
43 gfx::Rect* row_bounds,
44 int button_height) {
42 if (!button) 45 if (!button)
43 return; 46 return;
44 47
45 const gfx::Size size = button->GetPreferredSize(); 48 const gfx::Size size = button->GetPreferredSize();
46 row_bounds->set_width(row_bounds->width() - size.width()); 49 row_bounds->set_width(row_bounds->width() - size.width());
47 button->SetBounds(row_bounds->right(), row_bounds->y(), 50 button->SetBounds(
msw 2016/08/05 01:31:12 nit: DCHECK_LE(button_height, row_bounds->height()
juncai 2016/08/05 20:37:46 Done.
48 size.width(), row_bounds->height()); 51 row_bounds->right(),
52 row_bounds->y() + (row_bounds->height() - button_height) / 2,
53 size.width(), button_height);
49 row_bounds->set_width(row_bounds->width() - kRelatedButtonHSpacing); 54 row_bounds->set_width(row_bounds->width() - kRelatedButtonHSpacing);
50 } 55 }
51 56
52 } // namespace 57 } // namespace
53 58
54 /////////////////////////////////////////////////////////////////////////////// 59 ///////////////////////////////////////////////////////////////////////////////
55 // DialogClientView, public: 60 // DialogClientView, public:
56 61
57 DialogClientView::DialogClientView(Widget* owner, View* contents_view) 62 DialogClientView::DialogClientView(Widget* owner, View* contents_view)
58 : ClientView(owner, contents_view), 63 : ClientView(owner, contents_view),
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 178
174 void DialogClientView::Layout() { 179 void DialogClientView::Layout() {
175 gfx::Rect bounds = GetContentsBounds(); 180 gfx::Rect bounds = GetContentsBounds();
176 181
177 // Layout the row containing the buttons and the extra view. 182 // Layout the row containing the buttons and the extra view.
178 if (has_dialog_buttons() || ShouldShow(extra_view_)) { 183 if (has_dialog_buttons() || ShouldShow(extra_view_)) {
179 bounds.Inset(GetButtonRowInsets()); 184 bounds.Inset(GetButtonRowInsets());
180 const int height = GetButtonsAndExtraViewRowHeight(); 185 const int height = GetButtonsAndExtraViewRowHeight();
181 gfx::Rect row_bounds(bounds.x(), bounds.bottom() - height, 186 gfx::Rect row_bounds(bounds.x(), bounds.bottom() - height,
182 bounds.width(), height); 187 bounds.width(), height);
188 // If the |extra_view_| is a also button, then the |button_height| is the
189 // maximum height of the three buttons, otherwise it is the maximum height
190 // of the ok and cancel buttons.
191 const int button_height =
192 CustomButton::AsCustomButton(extra_view_) ? height : GetButtonHeight();
183 if (kIsOkButtonOnLeftSide) { 193 if (kIsOkButtonOnLeftSide) {
184 LayoutButton(cancel_button_, &row_bounds); 194 LayoutButton(cancel_button_, &row_bounds, button_height);
185 LayoutButton(ok_button_, &row_bounds); 195 LayoutButton(ok_button_, &row_bounds, button_height);
186 } else { 196 } else {
187 LayoutButton(ok_button_, &row_bounds); 197 LayoutButton(ok_button_, &row_bounds, button_height);
188 LayoutButton(cancel_button_, &row_bounds); 198 LayoutButton(cancel_button_, &row_bounds, button_height);
189 } 199 }
190 if (extra_view_) { 200 if (extra_view_) {
191 int custom_padding = 0; 201 int custom_padding = 0;
192 if (has_dialog_buttons() && 202 if (has_dialog_buttons() &&
193 GetDialogDelegate()->GetExtraViewPadding(&custom_padding)) { 203 GetDialogDelegate()->GetExtraViewPadding(&custom_padding)) {
194 // The call to LayoutButton() will already have accounted for some of 204 // The call to LayoutButton() will already have accounted for some of
195 // the padding. 205 // the padding.
196 custom_padding -= kRelatedButtonHSpacing; 206 custom_padding -= kRelatedButtonHSpacing;
197 row_bounds.set_width(row_bounds.width() - custom_padding); 207 row_bounds.set_width(row_bounds.width() - custom_padding);
198 } 208 }
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 } else { 319 } else {
310 button = MdTextButton::CreateSecondaryUiButton(this, title); 320 button = MdTextButton::CreateSecondaryUiButton(this, title);
311 } 321 }
312 322
313 const int kDialogMinButtonWidth = 75; 323 const int kDialogMinButtonWidth = 75;
314 button->SetMinSize(gfx::Size(kDialogMinButtonWidth, 0)); 324 button->SetMinSize(gfx::Size(kDialogMinButtonWidth, 0));
315 button->SetGroup(kButtonGroup); 325 button->SetGroup(kButtonGroup);
316 return button; 326 return button;
317 } 327 }
318 328
319 int DialogClientView::GetButtonsAndExtraViewRowHeight() const { 329 int DialogClientView::GetButtonHeight() const {
320 int extra_view_height = ShouldShow(extra_view_) ? 330 return std::max(
321 extra_view_->GetPreferredSize().height() : 0;
322 int buttons_height = std::max(
323 ok_button_ ? ok_button_->GetPreferredSize().height() : 0, 331 ok_button_ ? ok_button_->GetPreferredSize().height() : 0,
324 cancel_button_ ? cancel_button_->GetPreferredSize().height() : 0); 332 cancel_button_ ? cancel_button_->GetPreferredSize().height() : 0);
325 return std::max(extra_view_height, buttons_height); 333 }
334
335 int DialogClientView::GetExtraViewHeight() const {
336 return ShouldShow(extra_view_) ? extra_view_->GetPreferredSize().height() : 0;
337 }
338
339 int DialogClientView::GetButtonsAndExtraViewRowHeight() const {
340 return std::max(GetExtraViewHeight(), GetButtonHeight());
326 } 341 }
327 342
328 gfx::Insets DialogClientView::GetButtonRowInsets() const { 343 gfx::Insets DialogClientView::GetButtonRowInsets() const {
329 return GetButtonsAndExtraViewRowHeight() == 0 ? gfx::Insets() 344 return GetButtonsAndExtraViewRowHeight() == 0 ? gfx::Insets()
330 : button_row_insets_; 345 : button_row_insets_;
331 } 346 }
332 347
333 void DialogClientView::SetupFocusChain() { 348 void DialogClientView::SetupFocusChain() {
334 // Create a vector of child views in the order of intended focus. 349 // Create a vector of child views in the order of intended focus.
335 std::vector<View*> child_views; 350 std::vector<View*> child_views;
(...skipping 12 matching lines...) Expand all
348 std::remove(child_views.begin(), child_views.end(), nullptr), 363 std::remove(child_views.begin(), child_views.end(), nullptr),
349 child_views.end()); 364 child_views.end());
350 365
351 // Setup focus by reordering views. It is not safe to use SetNextFocusableView 366 // Setup focus by reordering views. It is not safe to use SetNextFocusableView
352 // since child views may be added externally to this view. 367 // since child views may be added externally to this view.
353 for (size_t i = 0; i < child_views.size(); i++) 368 for (size_t i = 0; i < child_views.size(); i++)
354 ReorderChildView(child_views[i], i); 369 ReorderChildView(child_views[i], i);
355 } 370 }
356 371
357 } // namespace views 372 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/window/dialog_client_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698