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

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

Issue 2571613002: Convert Register Protocol Handler dialog for Harmony/Material Design (Closed)
Patch Set: More fixed nits Created 3 years, 11 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/views_delegate.cc ('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/border.h"
13 #include "ui/views/controls/button/blue_button.h" 14 #include "ui/views/controls/button/blue_button.h"
14 #include "ui/views/controls/button/custom_button.h" 15 #include "ui/views/controls/button/custom_button.h"
15 #include "ui/views/controls/button/label_button.h" 16 #include "ui/views/controls/button/label_button.h"
16 #include "ui/views/controls/button/md_text_button.h" 17 #include "ui/views/controls/button/md_text_button.h"
17 #include "ui/views/layout/layout_constants.h" 18 #include "ui/views/layout/layout_constants.h"
18 #include "ui/views/style/platform_style.h" 19 #include "ui/views/style/platform_style.h"
19 #include "ui/views/views_delegate.h" 20 #include "ui/views/views_delegate.h"
20 #include "ui/views/widget/widget.h" 21 #include "ui/views/widget/widget.h"
21 #include "ui/views/window/dialog_delegate.h" 22 #include "ui/views/window/dialog_delegate.h"
22 23
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 row_bounds->set_width(row_bounds->width() - spacing); 62 row_bounds->set_width(row_bounds->width() - spacing);
62 } 63 }
63 64
64 } // namespace 65 } // namespace
65 66
66 /////////////////////////////////////////////////////////////////////////////// 67 ///////////////////////////////////////////////////////////////////////////////
67 // DialogClientView, public: 68 // DialogClientView, public:
68 69
69 DialogClientView::DialogClientView(Widget* owner, View* contents_view) 70 DialogClientView::DialogClientView(Widget* owner, View* contents_view)
70 : ClientView(owner, contents_view), 71 : ClientView(owner, contents_view),
71 button_row_insets_(0,
72 kButtonHEdgeMarginNew,
73 kButtonVEdgeMarginNew,
74 kButtonHEdgeMarginNew),
75 ok_button_(nullptr), 72 ok_button_(nullptr),
76 cancel_button_(nullptr), 73 cancel_button_(nullptr),
77 extra_view_(nullptr), 74 extra_view_(nullptr),
78 delegate_allowed_close_(false) { 75 delegate_allowed_close_(false) {
76 button_row_insets_ =
77 ViewsDelegate::GetInstance()
78 ? ViewsDelegate::GetInstance()->GetDialogButtonInsets()
79 : gfx::Insets(0, kButtonHEdgeMarginNew, kButtonVEdgeMarginNew,
80 kButtonHEdgeMarginNew);
79 // Doing this now ensures this accelerator will have lower priority than 81 // Doing this now ensures this accelerator will have lower priority than
80 // one set by the contents view. 82 // one set by the contents view.
81 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); 83 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE));
82 84
83 if (ViewsDelegate::GetInstance()) 85 if (ViewsDelegate::GetInstance())
84 button_row_insets_ = ViewsDelegate::GetInstance()->GetDialogButtonInsets(); 86 button_row_insets_ = ViewsDelegate::GetInstance()->GetDialogButtonInsets();
85 } 87 }
86 88
87 DialogClientView::~DialogClientView() { 89 DialogClientView::~DialogClientView() {
88 } 90 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 return this; 154 return this;
153 } 155 }
154 156
155 //////////////////////////////////////////////////////////////////////////////// 157 ////////////////////////////////////////////////////////////////////////////////
156 // DialogClientView, View overrides: 158 // DialogClientView, View overrides:
157 159
158 gfx::Size DialogClientView::GetPreferredSize() const { 160 gfx::Size DialogClientView::GetPreferredSize() const {
159 // Initialize the size to fit the buttons and extra view row. 161 // Initialize the size to fit the buttons and extra view row.
160 int extra_view_padding = 0; 162 int extra_view_padding = 0;
161 if (!GetDialogDelegate()->GetExtraViewPadding(&extra_view_padding)) 163 if (!GetDialogDelegate()->GetExtraViewPadding(&extra_view_padding))
162 extra_view_padding = kRelatedButtonHSpacing; 164 extra_view_padding = ViewsDelegate::GetInstance()
165 ? ViewsDelegate::GetInstance()
166 ->GetDialogRelatedButtonHorizontalSpacing()
167 : kRelatedButtonHSpacing;
163 gfx::Size size( 168 gfx::Size size(
164 (ok_button_ ? ok_button_->GetPreferredSize().width() : 0) + 169 (ok_button_ ? ok_button_->GetPreferredSize().width() : 0) +
165 (cancel_button_ ? cancel_button_->GetPreferredSize().width() : 0) + 170 (cancel_button_ ? cancel_button_->GetPreferredSize().width() : 0) +
166 (cancel_button_ && ok_button_ ? kRelatedButtonHSpacing : 0) + 171 (cancel_button_ && ok_button_
172 ? (ViewsDelegate::GetInstance()
173 ? ViewsDelegate::GetInstance()
174 ->GetDialogRelatedButtonHorizontalSpacing()
175 : kRelatedButtonHSpacing) : 0) +
167 (ShouldShow(extra_view_) ? extra_view_->GetPreferredSize().width() : 0) + 176 (ShouldShow(extra_view_) ? extra_view_->GetPreferredSize().width() : 0) +
168 (ShouldShow(extra_view_) && has_dialog_buttons() ? 177 (ShouldShow(extra_view_) && has_dialog_buttons() ? extra_view_padding
169 extra_view_padding : 0), 178 : 0),
170 0); 179 0);
171 180
172 int buttons_height = GetButtonsAndExtraViewRowHeight(); 181 int buttons_height = GetButtonsAndExtraViewRowHeight();
173 if (buttons_height != 0) { 182 if (buttons_height != 0) {
174 size.Enlarge(0, buttons_height + GetButtonsAndExtraViewRowTopPadding()); 183 size.Enlarge(0, buttons_height + GetButtonsAndExtraViewRowTopPadding());
175 // Inset the buttons and extra view. 184 // Inset the buttons and extra view.
176 const gfx::Insets insets = GetButtonRowInsets(); 185 const gfx::Insets insets = GetButtonRowInsets();
177 size.Enlarge(insets.width(), insets.height()); 186 size.Enlarge(insets.width(), insets.height());
178 } 187 }
179 188
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 gfx::Insets DialogClientView::GetButtonRowInsets() const { 369 gfx::Insets DialogClientView::GetButtonRowInsets() const {
361 return GetButtonsAndExtraViewRowHeight() == 0 ? gfx::Insets() 370 return GetButtonsAndExtraViewRowHeight() == 0 ? gfx::Insets()
362 : button_row_insets_; 371 : button_row_insets_;
363 } 372 }
364 373
365 int DialogClientView::GetButtonsAndExtraViewRowTopPadding() const { 374 int DialogClientView::GetButtonsAndExtraViewRowTopPadding() const {
366 int spacing = button_row_insets_.top(); 375 int spacing = button_row_insets_.top();
367 // Some subclasses of DialogClientView, in order to do their own layout, set 376 // Some subclasses of DialogClientView, in order to do their own layout, set
368 // button_row_insets_ to gfx::Insets(). To avoid breaking behavior of those 377 // button_row_insets_ to gfx::Insets(). To avoid breaking behavior of those
369 // dialogs, supplying 0 for the top inset of the row falls back to 378 // dialogs, supplying 0 for the top inset of the row falls back to
379 // ViewsDelegate::GetRelatedControlVerticalSpacing or
370 // kRelatedControlVerticalSpacing. 380 // kRelatedControlVerticalSpacing.
371 // TODO(ellyjones): Figure out a more principled way to approach that issue.
372 if (!spacing) 381 if (!spacing)
373 spacing = kRelatedControlVerticalSpacing; 382 spacing = ViewsDelegate::GetInstance()
383 ? ViewsDelegate::GetInstance()
384 ->GetDialogRelatedControlVerticalSpacing()
385 : kRelatedControlVerticalSpacing;
374 return spacing; 386 return spacing;
375 } 387 }
376 388
377 void DialogClientView::SetupFocusChain() { 389 void DialogClientView::SetupFocusChain() {
378 // Create a vector of child views in the order of intended focus. 390 // Create a vector of child views in the order of intended focus.
379 std::vector<View*> child_views; 391 std::vector<View*> child_views;
380 child_views.push_back(contents_view()); 392 child_views.push_back(contents_view());
381 child_views.push_back(extra_view_); 393 child_views.push_back(extra_view_);
382 if (kIsOkButtonOnLeftSide) { 394 if (kIsOkButtonOnLeftSide) {
383 child_views.push_back(ok_button_); 395 child_views.push_back(ok_button_);
384 child_views.push_back(cancel_button_); 396 child_views.push_back(cancel_button_);
385 } else { 397 } else {
386 child_views.push_back(cancel_button_); 398 child_views.push_back(cancel_button_);
387 child_views.push_back(ok_button_); 399 child_views.push_back(ok_button_);
388 } 400 }
389 401
390 // Remove all null views from the vector. 402 // Remove all null views from the vector.
391 child_views.erase( 403 child_views.erase(
392 std::remove(child_views.begin(), child_views.end(), nullptr), 404 std::remove(child_views.begin(), child_views.end(), nullptr),
393 child_views.end()); 405 child_views.end());
394 406
395 // Setup focus by reordering views. It is not safe to use SetNextFocusableView 407 // Setup focus by reordering views. It is not safe to use SetNextFocusableView
396 // since child views may be added externally to this view. 408 // since child views may be added externally to this view.
397 for (size_t i = 0; i < child_views.size(); i++) 409 for (size_t i = 0; i < child_views.size(); i++)
398 ReorderChildView(child_views[i], i); 410 ReorderChildView(child_views[i], i);
399 } 411 }
400 412
401 } // namespace views 413 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/views_delegate.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698