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

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

Issue 2750063002: views: implement dialog width snapping (Closed)
Patch Set: Created 3 years, 9 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"
(...skipping 23 matching lines...) Expand all
34 #else 34 #else
35 const bool kIsOkButtonOnLeftSide = false; 35 const bool kIsOkButtonOnLeftSide = false;
36 #endif 36 #endif
37 37
38 // Returns true if the given view should be shown (i.e. exists and is 38 // Returns true if the given view should be shown (i.e. exists and is
39 // visible). 39 // visible).
40 bool ShouldShow(View* view) { 40 bool ShouldShow(View* view) {
41 return view && view->visible(); 41 return view && view->visible();
42 } 42 }
43 43
44 // Snaps the width of |size| up to the next multiple of |unit|.
45 gfx::Size SnapWidthToMultipleOf(gfx::Size size, int unit) {
46 size.Enlarge(unit - 1, 0);
tapted 2017/03/15 22:26:11 I find it a bit weird to manipulate the size in al
Peter Kasting 2017/03/21 19:17:03 FWIW, always manipulating reads OK to me, but in m
47 size.set_width(size.width() - (size.width() % unit));
48 return size;
49 }
50
44 // Returns the bounding box required to contain |size1| and |size2|, placed one 51 // Returns the bounding box required to contain |size1| and |size2|, placed one
45 // atop the other. 52 // atop the other.
Peter Kasting 2017/03/21 19:17:03 I wonder if this function is the wrong place to im
46 gfx::Size GetBoundingSizeForVerticalStack(const gfx::Size& size1, 53 gfx::Size GetBoundingSizeForVerticalStack(const gfx::Size& size1,
tapted 2017/03/15 22:26:11 rename -> GetSnappedBoundingSize?
47 const gfx::Size& size2) { 54 const gfx::Size& size2) {
48 return gfx::Size(std::max(size1.width(), size2.width()), 55 return SnapWidthToMultipleOf(
49 size1.height() + size2.height()); 56 gfx::Size(std::max(size1.width(), size2.width()),
57 size1.height() + size2.height()),
58 ViewsDelegate::GetInstance()->GetDistanceMetric(
59 views::DistanceMetric::DIALOG_WIDTH_SNAPPING_UNIT));
tapted 2017/03/15 22:26:11 This is the ClientView - I think we need to take i
50 } 60 }
51 61
52 } // namespace 62 } // namespace
53 63
54 // Simple container to bubble child view changes up the view hierarchy. 64 // Simple container to bubble child view changes up the view hierarchy.
55 class DialogClientView::ButtonRowContainer : public View { 65 class DialogClientView::ButtonRowContainer : public View {
56 public: 66 public:
57 explicit ButtonRowContainer(DialogClientView* owner) : owner_(owner) {} 67 explicit ButtonRowContainer(DialogClientView* owner) : owner_(owner) {}
58 68
59 // View: 69 // View:
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 } 133 }
124 134
125 const DialogClientView* DialogClientView::AsDialogClientView() const { 135 const DialogClientView* DialogClientView::AsDialogClientView() const {
126 return this; 136 return this;
127 } 137 }
128 138
129 //////////////////////////////////////////////////////////////////////////////// 139 ////////////////////////////////////////////////////////////////////////////////
130 // DialogClientView, View overrides: 140 // DialogClientView, View overrides:
131 141
132 gfx::Size DialogClientView::GetPreferredSize() const { 142 gfx::Size DialogClientView::GetPreferredSize() const {
133 return GetBoundingSizeForVerticalStack( 143 return GetBoundingSizeForVerticalStack(
tapted 2017/03/15 22:26:11 Do we also need to consider the 3 "preferred" dial
Peter Kasting 2017/03/21 19:17:03 I'm wondering if you're asking about the same thin
134 ClientView::GetPreferredSize(), 144 ClientView::GetPreferredSize(),
135 button_row_container_->GetPreferredSize()); 145 button_row_container_->GetPreferredSize());
136 } 146 }
137 147
138 gfx::Size DialogClientView::GetMinimumSize() const { 148 gfx::Size DialogClientView::GetMinimumSize() const {
139 return GetBoundingSizeForVerticalStack( 149 return GetBoundingSizeForVerticalStack(
140 ClientView::GetMinimumSize(), button_row_container_->GetMinimumSize()); 150 ClientView::GetMinimumSize(), button_row_container_->GetMinimumSize());
141 } 151 }
142 152
143 gfx::Size DialogClientView::GetMaximumSize() const { 153 gfx::Size DialogClientView::GetMaximumSize() const {
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 423
414 if (extra_view_) 424 if (extra_view_)
415 return; 425 return;
416 426
417 extra_view_ = GetDialogDelegate()->CreateExtraView(); 427 extra_view_ = GetDialogDelegate()->CreateExtraView();
418 if (extra_view_) 428 if (extra_view_)
419 extra_view_->SetGroup(kButtonGroup); 429 extra_view_->SetGroup(kButtonGroup);
420 } 430 }
421 431
422 } // namespace views 432 } // 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