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

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: feedback from xiyuan 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 46
47 LoginWebDialog::LoginWebDialog(content::BrowserContext* browser_context, 47 LoginWebDialog::LoginWebDialog(content::BrowserContext* browser_context,
48 Delegate* delegate, 48 Delegate* delegate,
49 gfx::NativeWindow parent_window, 49 gfx::NativeWindow parent_window,
50 const base::string16& title, 50 const base::string16& title,
51 const GURL& url) 51 const GURL& url)
52 : browser_context_(browser_context), 52 : browser_context_(browser_context),
53 parent_window_(parent_window), 53 parent_window_(parent_window),
54 delegate_(delegate), 54 delegate_(delegate),
55 title_(title), 55 title_(title),
56 url_(url), 56 url_(url) {
57 is_open_(false) {
58 gfx::Rect screen_bounds(CalculateScreenBounds(gfx::Size())); 57 gfx::Rect screen_bounds(CalculateScreenBounds(gfx::Size()));
59 width_ = static_cast<int>(kDefaultWidthRatio * screen_bounds.width()); 58 width_ = static_cast<int>(kDefaultWidthRatio * screen_bounds.width());
60 height_ = static_cast<int>(kDefaultHeightRatio * screen_bounds.height()); 59 height_ = static_cast<int>(kDefaultHeightRatio * screen_bounds.height());
60
61 // Registers 'Shift + Browser Back' accelerator to web dialog, which allows
62 // Chrome OS CFM remote controller using hangup button to close dialog.
63 accelerators_.push_back(
64 ui::Accelerator(ui::VKEY_BROWSER_BACK, ui::EF_SHIFT_DOWN));
xiyuan 2017/05/11 04:48:27 Move this into GetAccelerators and get rid of |acc
Qiang(Joe) Xu 2017/05/12 21:50:45 Done.
61 } 65 }
62 66
63 LoginWebDialog::~LoginWebDialog() {} 67 LoginWebDialog::~LoginWebDialog() {}
64 68
65 void LoginWebDialog::Show() { 69 void LoginWebDialog::Show() {
66 if (parent_window_) { 70 if (parent_window_) {
67 chrome::ShowWebDialog(parent_window_, browser_context_, this); 71 dialog_window_ =
72 chrome::ShowWebDialog(parent_window_, browser_context_, this);
68 } else { 73 } else {
69 chrome::ShowWebDialogInContainer( 74 dialog_window_ = chrome::ShowWebDialogInContainer(
sky 2017/05/11 15:04:11 Initialize dialog_window_ to null.
Qiang(Joe) Xu 2017/05/12 21:50:45 Done.
70 SystemTrayClient::GetDialogParentContainerId(), browser_context_, this); 75 SystemTrayClient::GetDialogParentContainerId(), browser_context_, this);
71 } 76 }
72 is_open_ = true;
73 } 77 }
74 78
75 void LoginWebDialog::SetDialogSize(int width, int height) { 79 void LoginWebDialog::SetDialogSize(int width, int height) {
76 DCHECK_GE(width, 0); 80 DCHECK_GE(width, 0);
77 DCHECK_GE(height, 0); 81 DCHECK_GE(height, 0);
78 width_ = width; 82 width_ = width;
79 height_ = height; 83 height_ = height;
80 } 84 }
81 85
82 void LoginWebDialog::SetDialogTitle(const base::string16& title) { 86 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(); 125 auto& stack = g_web_contents_stack.Get();
122 return stack.empty() ? nullptr : stack.front(); 126 return stack.empty() ? nullptr : stack.front();
123 } 127 }
124 128
125 void LoginWebDialog::OnDialogShown(content::WebUI* webui, 129 void LoginWebDialog::OnDialogShown(content::WebUI* webui,
126 content::RenderViewHost* render_view_host) { 130 content::RenderViewHost* render_view_host) {
127 g_web_contents_stack.Pointer()->push_front(webui->GetWebContents()); 131 g_web_contents_stack.Pointer()->push_front(webui->GetWebContents());
128 } 132 }
129 133
130 void LoginWebDialog::OnDialogClosed(const std::string& json_retval) { 134 void LoginWebDialog::OnDialogClosed(const std::string& json_retval) {
131 is_open_ = false; 135 dialog_window_ = nullptr;
132 if (delegate_) 136 if (delegate_)
133 delegate_->OnDialogClosed(); 137 delegate_->OnDialogClosed();
134 delete this; 138 delete this;
135 } 139 }
136 140
137 void LoginWebDialog::OnCloseContents(WebContents* source, 141 void LoginWebDialog::OnCloseContents(WebContents* source,
138 bool* out_close_dialog) { 142 bool* out_close_dialog) {
139 *out_close_dialog = true; 143 *out_close_dialog = true;
140 144
141 if (GetCurrentWebContents() == source) 145 if (GetCurrentWebContents() == source)
(...skipping 21 matching lines...) Expand all
163 // fire an auto-reload, which in turn leads to opening a new browser window, 167 // fire an auto-reload, which in turn leads to opening a new browser window,
164 // so we must suppress it. 168 // so we must suppress it.
165 // http://crbug.com/443096 169 // http://crbug.com/443096
166 return (source && !chrome::FindBrowserWithWebContents(source)); 170 return (source && !chrome::FindBrowserWithWebContents(source));
167 } 171 }
168 172
169 bool LoginWebDialog::HandleShouldCreateWebContents() { 173 bool LoginWebDialog::HandleShouldCreateWebContents() {
170 return false; 174 return false;
171 } 175 }
172 176
177 std::vector<ui::Accelerator> LoginWebDialog::GetAccelerators() {
178 return accelerators_;
179 }
180
181 bool LoginWebDialog::AcceleratorPressed(const ui::Accelerator& accelerator) {
182 if (!dialog_window_)
183 return false;
184
185 if (accelerator.key_code() == ui::VKEY_BROWSER_BACK &&
sky 2017/05/11 15:04:11 Have a function that you use to get the accelerato
Qiang(Joe) Xu 2017/05/12 21:50:45 Done.
186 accelerator.IsShiftDown()) {
187 views::Widget::GetWidgetForNativeWindow(dialog_window_)->Close();
188 return true;
189 }
190
191 return false;
192 }
193
173 } // namespace chromeos 194 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698