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

Side by Side Diff: chrome/browser/ui/views/extensions/chooser_dialog_view.cc

Issue 2654323002: harmony: convert device chooser (Closed)
Patch Set: fix dialog width 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "chrome/browser/ui/views/extensions/chooser_dialog_view.h" 5 #include "chrome/browser/ui/views/extensions/chooser_dialog_view.h"
6 6
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "base/threading/thread_task_runner_handle.h" 8 #include "base/threading/thread_task_runner_handle.h"
9 #include "chrome/browser/chooser_controller/chooser_controller.h" 9 #include "chrome/browser/chooser_controller/chooser_controller.h"
10 #include "chrome/browser/extensions/api/chrome_device_permissions_prompt.h" 10 #include "chrome/browser/extensions/api/chrome_device_permissions_prompt.h"
11 #include "chrome/browser/extensions/chrome_extension_chooser_dialog.h" 11 #include "chrome/browser/extensions/chrome_extension_chooser_dialog.h"
12 #include "chrome/browser/extensions/device_permissions_dialog_controller.h" 12 #include "chrome/browser/extensions/device_permissions_dialog_controller.h"
13 #include "chrome/browser/ui/views/device_chooser_content_view.h" 13 #include "chrome/browser/ui/views/device_chooser_content_view.h"
14 #include "chrome/browser/ui/views/harmony/layout_delegate.h"
14 #include "components/constrained_window/constrained_window_views.h" 15 #include "components/constrained_window/constrained_window_views.h"
15 #include "components/web_modal/web_contents_modal_dialog_manager.h" 16 #include "components/web_modal/web_contents_modal_dialog_manager.h"
16 #include "content/public/browser/browser_thread.h" 17 #include "content/public/browser/browser_thread.h"
17 #include "ui/gfx/geometry/insets.h" 18 #include "ui/gfx/geometry/insets.h"
19 #include "ui/views/background.h"
18 #include "ui/views/controls/link.h" 20 #include "ui/views/controls/link.h"
19 #include "ui/views/controls/styled_label.h" 21 #include "ui/views/controls/styled_label.h"
20 #include "ui/views/layout/layout_constants.h" 22 #include "ui/views/layout/fill_layout.h"
21 #include "ui/views/window/dialog_client_view.h" 23 #include "ui/views/window/dialog_client_view.h"
22 24
25 namespace {
26
27 LayoutDelegate::LayoutDistanceType GetContentViewToButtonsDistanceType() {
28 // Hack: in the old layout, the buttons are related to the content view, but
29 // in the Harmony layout they are unrelated, so the layout distance type is
30 // variable.
Peter Kasting 2017/02/01 02:39:25 Unless the function of the buttons have changed, t
31 return LayoutDelegate::Get()->IsHarmonyMode()
32 ? LayoutDelegate::LayoutDistanceType::
33 UNRELATED_CONTROL_VERTICAL_SPACING
34 : LayoutDelegate::LayoutDistanceType::
35 RELATED_CONTROL_VERTICAL_SPACING;
36 }
37
38 } // namespace
39
23 ChooserDialogView::ChooserDialogView( 40 ChooserDialogView::ChooserDialogView(
24 std::unique_ptr<ChooserController> chooser_controller) { 41 std::unique_ptr<ChooserController> chooser_controller) {
25 // ------------------------------------ 42 // ------------------------------------
26 // | Chooser dialog title | 43 // | Chooser dialog title |
27 // | -------------------------------- | 44 // | -------------------------------- |
28 // | | option 0 | | 45 // | | option 0 | |
29 // | | option 1 | | 46 // | | option 1 | |
30 // | | option 2 | | 47 // | | option 2 | |
31 // | | | | 48 // | | | |
32 // | | | | 49 // | | | |
33 // | | | | 50 // | | | |
34 // | -------------------------------- | 51 // | -------------------------------- |
35 // | [ Connect ] [ Cancel ] | 52 // | [ Connect ] [ Cancel ] |
36 // |----------------------------------| 53 // |----------------------------------|
37 // | Get help | 54 // | Get help |
38 // ------------------------------------ 55 // ------------------------------------
39 56
40 DCHECK(chooser_controller); 57 DCHECK(chooser_controller);
41 device_chooser_content_view_ = 58 device_chooser_content_view_ =
42 new DeviceChooserContentView(this, std::move(chooser_controller)); 59 new DeviceChooserContentView(this, std::move(chooser_controller));
60
61 LayoutDelegate* delegate = LayoutDelegate::Get();
62 if (delegate->IsHarmonyMode()) {
Peter Kasting 2017/02/01 02:39:26 I'd like to avoid IsHarmonyMode() here. The first
63 gfx::Size size = device_chooser_content_view_->GetPreferredSize();
64 int inset_width =
65 2 *
66 delegate->GetLayoutDistance(
67 LayoutDelegate::LayoutDistanceType::PANEL_HORIZ_MARGIN);
68 size.set_width(delegate->GetDialogPreferredWidth(
69 LayoutDelegate::DialogWidthType::MEDIUM) -
70 2 * inset_width);
Peter Kasting 2017/02/01 02:39:26 How come this is 2 * inset_width instead of just i
71 device_chooser_content_view_->SetPreferredSize(size);
72 }
43 } 73 }
44 74
45 ChooserDialogView::~ChooserDialogView() {} 75 ChooserDialogView::~ChooserDialogView() {}
46 76
47 base::string16 ChooserDialogView::GetWindowTitle() const { 77 base::string16 ChooserDialogView::GetWindowTitle() const {
48 return device_chooser_content_view_->GetWindowTitle(); 78 return device_chooser_content_view_->GetWindowTitle();
49 } 79 }
50 80
51 bool ChooserDialogView::ShouldShowCloseButton() const { 81 bool ChooserDialogView::ShouldShowCloseButton() const {
52 return false; 82 return false;
(...skipping 12 matching lines...) Expand all
65 return device_chooser_content_view_->IsDialogButtonEnabled(button); 95 return device_chooser_content_view_->IsDialogButtonEnabled(button);
66 } 96 }
67 97
68 views::View* ChooserDialogView::CreateFootnoteView() { 98 views::View* ChooserDialogView::CreateFootnoteView() {
69 return device_chooser_content_view_->footnote_link(); 99 return device_chooser_content_view_->footnote_link();
70 } 100 }
71 101
72 views::ClientView* ChooserDialogView::CreateClientView(views::Widget* widget) { 102 views::ClientView* ChooserDialogView::CreateClientView(views::Widget* widget) {
73 views::DialogClientView* client = 103 views::DialogClientView* client =
74 new views::DialogClientView(widget, GetContentsView()); 104 new views::DialogClientView(widget, GetContentsView());
75 client->set_button_row_insets(gfx::Insets()); 105 LayoutDelegate* delegate = LayoutDelegate::Get();
106 client->set_button_row_insets(gfx::Insets(
107 delegate->GetLayoutDistance(GetContentViewToButtonsDistanceType()), 0, 0,
108 0));
76 return client; 109 return client;
77 } 110 }
78 111
79 views::NonClientFrameView* ChooserDialogView::CreateNonClientFrameView( 112 views::NonClientFrameView* ChooserDialogView::CreateNonClientFrameView(
80 views::Widget* widget) { 113 views::Widget* widget) {
81 // ChooserDialogView always has a parent, so ShouldUseCustomFrame() should 114 // ChooserDialogView always has a parent, so ShouldUseCustomFrame() should
82 // always be true. 115 // always be true.
83 DCHECK(ShouldUseCustomFrame()); 116 DCHECK(ShouldUseCustomFrame());
117 LayoutDelegate* delegate = LayoutDelegate::Get();
84 return views::DialogDelegate::CreateDialogFrameView( 118 return views::DialogDelegate::CreateDialogFrameView(
85 widget, gfx::Insets(views::kPanelVertMargin, views::kPanelHorizMargin, 119 widget,
86 views::kPanelVertMargin, views::kPanelHorizMargin)); 120 gfx::Insets(delegate->GetLayoutDistance(
121 LayoutDelegate::LayoutDistanceType::PANEL_VERT_MARGIN),
122 delegate->GetLayoutDistance(
123 LayoutDelegate::LayoutDistanceType::PANEL_HORIZ_MARGIN)));
87 } 124 }
88 125
89 bool ChooserDialogView::Accept() { 126 bool ChooserDialogView::Accept() {
90 device_chooser_content_view_->Accept(); 127 device_chooser_content_view_->Accept();
91 return true; 128 return true;
92 } 129 }
93 130
94 bool ChooserDialogView::Cancel() { 131 bool ChooserDialogView::Cancel() {
95 device_chooser_content_view_->Cancel(); 132 device_chooser_content_view_->Cancel();
96 return true; 133 return true;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 void ChromeDevicePermissionsPrompt::ShowDialogViews() { 175 void ChromeDevicePermissionsPrompt::ShowDialogViews() {
139 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 176 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
140 177
141 std::unique_ptr<ChooserController> chooser_controller( 178 std::unique_ptr<ChooserController> chooser_controller(
142 new DevicePermissionsDialogController(web_contents()->GetMainFrame(), 179 new DevicePermissionsDialogController(web_contents()->GetMainFrame(),
143 prompt())); 180 prompt()));
144 181
145 constrained_window::ShowWebModalDialogViews( 182 constrained_window::ShowWebModalDialogViews(
146 new ChooserDialogView(std::move(chooser_controller)), web_contents()); 183 new ChooserDialogView(std::move(chooser_controller)), web_contents());
147 } 184 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698