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

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

Issue 2625083003: Implement Harmony-style consistent button widths for Collected Cookies. (Closed)
Patch Set: Start on DialogClientview Created 3 years, 10 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') | ui/views/window/dialog_client_view_unittest.cc » ('j') | 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 86
87 void DialogClientView::CancelWindow() { 87 void DialogClientView::CancelWindow() {
88 // Only notify the delegate once. See |delegate_allowed_close_|'s comment. 88 // Only notify the delegate once. See |delegate_allowed_close_|'s comment.
89 if (!delegate_allowed_close_ && GetDialogDelegate()->Cancel()) { 89 if (!delegate_allowed_close_ && GetDialogDelegate()->Cancel()) {
90 delegate_allowed_close_ = true; 90 delegate_allowed_close_ = true;
91 GetWidget()->Close(); 91 GetWidget()->Close();
92 } 92 }
93 } 93 }
94 94
95 void DialogClientView::UpdateDialogButtons() { 95 void DialogClientView::UpdateDialogButtons() {
96 const int buttons = GetDialogDelegate()->GetDialogButtons(); 96 SetupLayout();
97 97 SetupViews();
98 if (buttons & ui::DIALOG_BUTTON_OK) {
99 if (!ok_button_) {
100 ok_button_ = CreateDialogButton(ui::DIALOG_BUTTON_OK);
101 AddChildView(ok_button_);
102 }
103
104 GetDialogDelegate()->UpdateButton(ok_button_, ui::DIALOG_BUTTON_OK);
105 } else if (ok_button_) {
106 delete ok_button_;
107 ok_button_ = nullptr;
108 }
109
110 if (buttons & ui::DIALOG_BUTTON_CANCEL) {
111 if (!cancel_button_) {
112 cancel_button_ = CreateDialogButton(ui::DIALOG_BUTTON_CANCEL);
113 AddChildView(cancel_button_);
114 }
115
116 GetDialogDelegate()->UpdateButton(cancel_button_, ui::DIALOG_BUTTON_CANCEL);
117 } else if (cancel_button_) {
118 delete cancel_button_;
119 cancel_button_ = nullptr;
120 }
121
122 SetupFocusChain(); 98 SetupFocusChain();
123 } 99 }
124 100
125 /////////////////////////////////////////////////////////////////////////////// 101 ///////////////////////////////////////////////////////////////////////////////
126 // DialogClientView, ClientView overrides: 102 // DialogClientView, ClientView overrides:
127 103
128 bool DialogClientView::CanClose() { 104 bool DialogClientView::CanClose() {
129 // If the dialog is closing but no Accept or Cancel action has been performed 105 // If the dialog is closing but no Accept or Cancel action has been performed
130 // before, it's a Close action. 106 // before, it's a Close action.
131 if (!delegate_allowed_close_) 107 if (!delegate_allowed_close_)
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 209
234 GetWidget()->Close(); 210 GetWidget()->Close();
235 return true; 211 return true;
236 } 212 }
237 213
238 void DialogClientView::ViewHierarchyChanged( 214 void DialogClientView::ViewHierarchyChanged(
239 const ViewHierarchyChangedDetails& details) { 215 const ViewHierarchyChangedDetails& details) {
240 ClientView::ViewHierarchyChanged(details); 216 ClientView::ViewHierarchyChanged(details);
241 if (details.is_add && details.child == this) { 217 if (details.is_add && details.child == this) {
242 UpdateDialogButtons(); 218 UpdateDialogButtons();
243 CreateExtraView();
244 } else if (!details.is_add && details.child != this) { 219 } else if (!details.is_add && details.child != this) {
245 if (details.child == ok_button_) 220 if (details.child == ok_button_)
246 ok_button_ = nullptr; 221 ok_button_ = nullptr;
247 else if (details.child == cancel_button_) 222 else if (details.child == cancel_button_)
248 cancel_button_ = nullptr; 223 cancel_button_ = nullptr;
249 else if (details.child == extra_view_) 224 else if (details.child == extra_view_)
250 extra_view_ = nullptr; 225 extra_view_ = nullptr;
251 } 226 }
252 } 227 }
253 228
(...skipping 18 matching lines...) Expand all
272 247
273 if (sender == ok_button_) 248 if (sender == ok_button_)
274 AcceptWindow(); 249 AcceptWindow();
275 else if (sender == cancel_button_) 250 else if (sender == cancel_button_)
276 CancelWindow(); 251 CancelWindow();
277 else 252 else
278 NOTREACHED(); 253 NOTREACHED();
279 } 254 }
280 255
281 //////////////////////////////////////////////////////////////////////////////// 256 ////////////////////////////////////////////////////////////////////////////////
282 // DialogClientView, protected: 257 // DialogClientView, private:
283
284 DialogClientView::DialogClientView(View* contents_view)
285 : ClientView(nullptr, contents_view),
286 ok_button_(nullptr),
287 cancel_button_(nullptr),
288 extra_view_(nullptr),
289 delegate_allowed_close_(false) {}
290 258
291 DialogDelegate* DialogClientView::GetDialogDelegate() const { 259 DialogDelegate* DialogClientView::GetDialogDelegate() const {
292 return GetWidget()->widget_delegate()->AsDialogDelegate(); 260 return GetWidget()->widget_delegate()->AsDialogDelegate();
293 } 261 }
294 262
295 void DialogClientView::CreateExtraView() {
296 if (extra_view_)
297 return;
298
299 extra_view_ = GetDialogDelegate()->CreateExtraView();
300 if (extra_view_) {
301 extra_view_->SetGroup(kButtonGroup);
302 AddChildView(extra_view_);
303 SetupFocusChain();
304 }
305 }
306
307 void DialogClientView::ChildPreferredSizeChanged(View* child) { 263 void DialogClientView::ChildPreferredSizeChanged(View* child) {
308 if (child == extra_view_) 264 if (child == extra_view_)
309 Layout(); 265 Layout();
310 } 266 }
311 267
312 void DialogClientView::ChildVisibilityChanged(View* child) { 268 void DialogClientView::ChildVisibilityChanged(View* child) {
313 ChildPreferredSizeChanged(child); 269 ChildPreferredSizeChanged(child);
314 } 270 }
315 271
316 ////////////////////////////////////////////////////////////////////////////////
317 // DialogClientView, private:
318
319 LabelButton* DialogClientView::CreateDialogButton(ui::DialogButton type) { 272 LabelButton* DialogClientView::CreateDialogButton(ui::DialogButton type) {
320 const base::string16 title = GetDialogDelegate()->GetDialogButtonLabel(type); 273 const base::string16 title = GetDialogDelegate()->GetDialogButtonLabel(type);
321 LabelButton* button = nullptr; 274 LabelButton* button = nullptr;
322 275
323 const bool is_default = 276 const bool is_default =
324 GetDialogDelegate()->GetDefaultDialogButton() == type && 277 GetDialogDelegate()->GetDefaultDialogButton() == type &&
325 (type != ui::DIALOG_BUTTON_CANCEL || 278 (type != ui::DIALOG_BUTTON_CANCEL ||
326 PlatformStyle::kDialogDefaultButtonCanBeCancel); 279 PlatformStyle::kDialogDefaultButtonCanBeCancel);
327 280
328 // The default button is always blue in Harmony. 281 // The default button is always blue in Harmony.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 // ViewsDelegate::GetRelatedControlVerticalSpacing. 320 // ViewsDelegate::GetRelatedControlVerticalSpacing.
368 // TODO(bsep): The top inset should never be 0 when harmony is enabled. 321 // TODO(bsep): The top inset should never be 0 when harmony is enabled.
369 const int top = button_row_insets_.top() == 0 322 const int top = button_row_insets_.top() == 0
370 ? ViewsDelegate::GetInstance() 323 ? ViewsDelegate::GetInstance()
371 ->GetDialogRelatedControlVerticalSpacing() 324 ->GetDialogRelatedControlVerticalSpacing()
372 : button_row_insets_.top(); 325 : button_row_insets_.top();
373 return gfx::Insets(top, button_row_insets_.left(), 326 return gfx::Insets(top, button_row_insets_.left(),
374 button_row_insets_.bottom(), button_row_insets_.right()); 327 button_row_insets_.bottom(), button_row_insets_.right());
375 } 328 }
376 329
330 void DialogClientView::SetupLayout() {
331 // TODO(tapted): Use a LayoutManager.
332 }
333
334 void DialogClientView::SetupViews() {
335 const int buttons = GetDialogDelegate()->GetDialogButtons();
336
337 if (buttons & ui::DIALOG_BUTTON_OK) {
338 if (!ok_button_) {
339 ok_button_ = CreateDialogButton(ui::DIALOG_BUTTON_OK);
340 AddChildView(ok_button_);
341 }
342
343 GetDialogDelegate()->UpdateButton(ok_button_, ui::DIALOG_BUTTON_OK);
344 } else if (ok_button_) {
345 delete ok_button_;
346 ok_button_ = nullptr;
347 }
348
349 if (buttons & ui::DIALOG_BUTTON_CANCEL) {
350 if (!cancel_button_) {
351 cancel_button_ = CreateDialogButton(ui::DIALOG_BUTTON_CANCEL);
352 AddChildView(cancel_button_);
353 }
354
355 GetDialogDelegate()->UpdateButton(cancel_button_, ui::DIALOG_BUTTON_CANCEL);
356 } else if (cancel_button_) {
357 delete cancel_button_;
358 cancel_button_ = nullptr;
359 }
360
361 if (extra_view_)
362 return;
363
364 extra_view_ = GetDialogDelegate()->CreateExtraView();
365 if (extra_view_) {
366 extra_view_->SetGroup(kButtonGroup);
367 AddChildView(extra_view_);
368 }
369 }
370
377 void DialogClientView::SetupFocusChain() { 371 void DialogClientView::SetupFocusChain() {
378 // Create a vector of child views in the order of intended focus. 372 // Create a vector of child views in the order of intended focus.
379 std::vector<View*> child_views; 373 std::vector<View*> child_views;
380 child_views.push_back(contents_view()); 374 child_views.push_back(contents_view());
381 child_views.push_back(extra_view_); 375 child_views.push_back(extra_view_);
382 if (kIsOkButtonOnLeftSide) { 376 if (kIsOkButtonOnLeftSide) {
383 child_views.push_back(ok_button_); 377 child_views.push_back(ok_button_);
384 child_views.push_back(cancel_button_); 378 child_views.push_back(cancel_button_);
385 } else { 379 } else {
386 child_views.push_back(cancel_button_); 380 child_views.push_back(cancel_button_);
387 child_views.push_back(ok_button_); 381 child_views.push_back(ok_button_);
388 } 382 }
389 383
390 // Remove all null views from the vector. 384 // Remove all null views from the vector.
391 child_views.erase( 385 child_views.erase(
392 std::remove(child_views.begin(), child_views.end(), nullptr), 386 std::remove(child_views.begin(), child_views.end(), nullptr),
393 child_views.end()); 387 child_views.end());
394 388
395 // Setup focus by reordering views. It is not safe to use SetNextFocusableView 389 // Setup focus by reordering views. It is not safe to use SetNextFocusableView
396 // since child views may be added externally to this view. 390 // since child views may be added externally to this view.
397 for (size_t i = 0; i < child_views.size(); i++) 391 for (size_t i = 0; i < child_views.size(); i++)
398 ReorderChildView(child_views[i], i); 392 ReorderChildView(child_views[i], i);
399 } 393 }
400 394
401 } // namespace views 395 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/window/dialog_client_view.h ('k') | ui/views/window/dialog_client_view_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698