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

Side by Side Diff: chrome/browser/chromeos/login/ui/login_web_dialog.cc

Issue 2871073002: cros: Bind hangup red button on remote controller to close web dialog (Closed)
Patch Set: added test coverage Created 3 years, 7 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/chromeos/login/ui/login_web_dialog.h" 5 #include "chrome/browser/chromeos/login/ui/login_web_dialog.h"
6 6
7 #include <deque> 7 #include <deque>
8 8
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 18 matching lines...) Expand all
29 const double kDefaultWidthRatio = 0.6; 29 const double kDefaultWidthRatio = 0.6;
30 const double kDefaultHeightRatio = 0.6; 30 const double kDefaultHeightRatio = 0.6;
31 31
32 // Default width/height ratio of minimal dialog size. 32 // Default width/height ratio of minimal dialog size.
33 const double kMinimumWidthRatio = 0.25; 33 const double kMinimumWidthRatio = 0.25;
34 const double kMinimumHeightRatio = 0.25; 34 const double kMinimumHeightRatio = 0.25;
35 35
36 base::LazyInstance<std::deque<WebContents*>>::DestructorAtExit 36 base::LazyInstance<std::deque<WebContents*>>::DestructorAtExit
37 g_web_contents_stack = LAZY_INSTANCE_INITIALIZER; 37 g_web_contents_stack = LAZY_INSTANCE_INITIALIZER;
38 38
39 // Returns the accelerator which is mapped as hangup button on Chrome OS CFM
40 // remote controller to close the dialog.
41 ui::Accelerator GetCloseAccelerator() {
42 return ui::Accelerator(ui::VKEY_BROWSER_BACK, ui::EF_SHIFT_DOWN);
43 }
44
39 } // namespace 45 } // namespace
40 46
41 /////////////////////////////////////////////////////////////////////////////// 47 ///////////////////////////////////////////////////////////////////////////////
42 // LoginWebDialog, public: 48 // LoginWebDialog, public:
43 49
44 void LoginWebDialog::Delegate::OnDialogClosed() { 50 void LoginWebDialog::Delegate::OnDialogClosed() {
45 } 51 }
46 52
47 LoginWebDialog::LoginWebDialog(content::BrowserContext* browser_context, 53 LoginWebDialog::LoginWebDialog(content::BrowserContext* browser_context,
48 Delegate* delegate, 54 Delegate* delegate,
49 gfx::NativeWindow parent_window, 55 gfx::NativeWindow parent_window,
50 const base::string16& title, 56 const base::string16& title,
51 const GURL& url) 57 const GURL& url)
52 : browser_context_(browser_context), 58 : browser_context_(browser_context),
53 parent_window_(parent_window), 59 parent_window_(parent_window),
54 delegate_(delegate), 60 delegate_(delegate),
55 title_(title), 61 title_(title),
56 url_(url), 62 url_(url) {
57 is_open_(false) {
58 gfx::Rect screen_bounds(CalculateScreenBounds(gfx::Size())); 63 gfx::Rect screen_bounds(CalculateScreenBounds(gfx::Size()));
59 width_ = static_cast<int>(kDefaultWidthRatio * screen_bounds.width()); 64 width_ = static_cast<int>(kDefaultWidthRatio * screen_bounds.width());
60 height_ = static_cast<int>(kDefaultHeightRatio * screen_bounds.height()); 65 height_ = static_cast<int>(kDefaultHeightRatio * screen_bounds.height());
61 } 66 }
62 67
63 LoginWebDialog::~LoginWebDialog() {} 68 LoginWebDialog::~LoginWebDialog() {}
64 69
65 void LoginWebDialog::Show() { 70 void LoginWebDialog::Show() {
71 dialog_window_ = nullptr;
66 if (parent_window_) { 72 if (parent_window_) {
67 chrome::ShowWebDialog(parent_window_, browser_context_, this); 73 dialog_window_ =
74 chrome::ShowWebDialog(parent_window_, browser_context_, this);
68 } else { 75 } else {
69 chrome::ShowWebDialogInContainer( 76 dialog_window_ = chrome::ShowWebDialogInContainer(
70 SystemTrayClient::GetDialogParentContainerId(), browser_context_, this); 77 SystemTrayClient::GetDialogParentContainerId(), browser_context_, this);
71 } 78 }
72 is_open_ = true;
73 } 79 }
74 80
75 void LoginWebDialog::SetDialogSize(int width, int height) { 81 void LoginWebDialog::SetDialogSize(int width, int height) {
76 DCHECK_GE(width, 0); 82 DCHECK_GE(width, 0);
77 DCHECK_GE(height, 0); 83 DCHECK_GE(height, 0);
78 width_ = width; 84 width_ = width;
79 height_ = height; 85 height_ = height;
80 } 86 }
81 87
82 void LoginWebDialog::SetDialogTitle(const base::string16& title) { 88 void LoginWebDialog::SetDialogTitle(const base::string16& title) {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 auto& stack = g_web_contents_stack.Get(); 127 auto& stack = g_web_contents_stack.Get();
122 return stack.empty() ? nullptr : stack.front(); 128 return stack.empty() ? nullptr : stack.front();
123 } 129 }
124 130
125 void LoginWebDialog::OnDialogShown(content::WebUI* webui, 131 void LoginWebDialog::OnDialogShown(content::WebUI* webui,
126 content::RenderViewHost* render_view_host) { 132 content::RenderViewHost* render_view_host) {
127 g_web_contents_stack.Pointer()->push_front(webui->GetWebContents()); 133 g_web_contents_stack.Pointer()->push_front(webui->GetWebContents());
128 } 134 }
129 135
130 void LoginWebDialog::OnDialogClosed(const std::string& json_retval) { 136 void LoginWebDialog::OnDialogClosed(const std::string& json_retval) {
131 is_open_ = false; 137 dialog_window_ = nullptr;
132 if (delegate_) 138 if (delegate_)
133 delegate_->OnDialogClosed(); 139 delegate_->OnDialogClosed();
134 delete this; 140 delete this;
135 } 141 }
136 142
137 void LoginWebDialog::OnCloseContents(WebContents* source, 143 void LoginWebDialog::OnCloseContents(WebContents* source,
138 bool* out_close_dialog) { 144 bool* out_close_dialog) {
139 *out_close_dialog = true; 145 *out_close_dialog = true;
140 146
141 if (GetCurrentWebContents() == source) 147 if (GetCurrentWebContents() == source)
(...skipping 21 matching lines...) Expand all
163 // fire an auto-reload, which in turn leads to opening a new browser window, 169 // fire an auto-reload, which in turn leads to opening a new browser window,
164 // so we must suppress it. 170 // so we must suppress it.
165 // http://crbug.com/443096 171 // http://crbug.com/443096
166 return (source && !chrome::FindBrowserWithWebContents(source)); 172 return (source && !chrome::FindBrowserWithWebContents(source));
167 } 173 }
168 174
169 bool LoginWebDialog::HandleShouldCreateWebContents() { 175 bool LoginWebDialog::HandleShouldCreateWebContents() {
170 return false; 176 return false;
171 } 177 }
172 178
179 std::vector<ui::Accelerator> LoginWebDialog::GetAccelerators() {
180 std::vector<ui::Accelerator> accelerators;
181 accelerators.push_back(GetCloseAccelerator());
182 return accelerators;
xiyuan 2017/05/12 22:29:57 nit: return {GetCloseAccelerator()};
Qiang(Joe) Xu 2017/05/12 22:39:32 Done.
183 }
184
185 bool LoginWebDialog::AcceleratorPressed(const ui::Accelerator& accelerator) {
186 if (!dialog_window_)
187 return false;
188
189 if (GetCloseAccelerator() == accelerator) {
190 views::Widget::GetWidgetForNativeWindow(dialog_window_)->Close();
191 return true;
192 }
193
194 return false;
195 }
196
173 } // namespace chromeos 197 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698