OLD | NEW |
---|---|
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/webui_login_view.h" | 5 #include "chrome/browser/chromeos/login/ui/webui_login_view.h" |
6 | 6 |
7 #include "ash/common/focus_cycler.h" | 7 #include "ash/common/focus_cycler.h" |
8 #include "ash/common/system/status_area_widget_delegate.h" | |
8 #include "ash/common/system/tray/system_tray.h" | 9 #include "ash/common/system/tray/system_tray.h" |
9 #include "ash/common/wm_shell.h" | 10 #include "ash/common/wm_shell.h" |
10 #include "ash/shell.h" | 11 #include "ash/shell.h" |
11 #include "base/bind.h" | 12 #include "base/bind.h" |
12 #include "base/callback.h" | 13 #include "base/callback.h" |
13 #include "base/i18n/rtl.h" | 14 #include "base/i18n/rtl.h" |
14 #include "base/logging.h" | 15 #include "base/logging.h" |
15 #include "base/macros.h" | 16 #include "base/macros.h" |
16 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
17 #include "base/trace_event/trace_event.h" | 18 #include "base/trace_event/trace_event.h" |
(...skipping 28 matching lines...) Expand all Loading... | |
46 #include "content/public/browser/render_widget_host.h" | 47 #include "content/public/browser/render_widget_host.h" |
47 #include "content/public/browser/render_widget_host_view.h" | 48 #include "content/public/browser/render_widget_host_view.h" |
48 #include "content/public/browser/web_contents.h" | 49 #include "content/public/browser/web_contents.h" |
49 #include "content/public/browser/web_ui.h" | 50 #include "content/public/browser/web_ui.h" |
50 #include "content/public/common/renderer_preferences.h" | 51 #include "content/public/common/renderer_preferences.h" |
51 #include "extensions/browser/view_type_utils.h" | 52 #include "extensions/browser/view_type_utils.h" |
52 #include "third_party/WebKit/public/web/WebInputEvent.h" | 53 #include "third_party/WebKit/public/web/WebInputEvent.h" |
53 #include "ui/gfx/geometry/rect.h" | 54 #include "ui/gfx/geometry/rect.h" |
54 #include "ui/gfx/geometry/size.h" | 55 #include "ui/gfx/geometry/size.h" |
55 #include "ui/views/controls/webview/webview.h" | 56 #include "ui/views/controls/webview/webview.h" |
57 #include "ui/views/focus/focus_manager.h" | |
58 #include "ui/views/focus/focus_search.h" | |
56 #include "ui/views/widget/widget.h" | 59 #include "ui/views/widget/widget.h" |
57 | 60 |
58 using content::NativeWebKeyboardEvent; | 61 using content::NativeWebKeyboardEvent; |
59 using content::RenderViewHost; | 62 using content::RenderViewHost; |
60 using content::WebContents; | 63 using content::WebContents; |
61 using web_modal::WebContentsModalDialogManager; | 64 using web_modal::WebContentsModalDialogManager; |
62 | 65 |
63 namespace { | 66 namespace { |
64 | 67 |
65 // These strings must be kept in sync with handleAccelerator() | 68 // These strings must be kept in sync with handleAccelerator() |
(...skipping 23 matching lines...) Expand all Loading... | |
89 ~ScopedArrowKeyTraversal() { | 92 ~ScopedArrowKeyTraversal() { |
90 views::FocusManager::set_arrow_key_traversal_enabled( | 93 views::FocusManager::set_arrow_key_traversal_enabled( |
91 previous_arrow_key_traversal_enabled_); | 94 previous_arrow_key_traversal_enabled_); |
92 } | 95 } |
93 | 96 |
94 private: | 97 private: |
95 const bool previous_arrow_key_traversal_enabled_; | 98 const bool previous_arrow_key_traversal_enabled_; |
96 DISALLOW_COPY_AND_ASSIGN(ScopedArrowKeyTraversal); | 99 DISALLOW_COPY_AND_ASSIGN(ScopedArrowKeyTraversal); |
97 }; | 100 }; |
98 | 101 |
102 // A helper method returns status area widget delegate if exists, | |
103 // otherwise nullptr. | |
104 ash::StatusAreaWidgetDelegate* GetStatusAreaWidgetDelegate() { | |
105 ash::SystemTray* tray = ash::Shell::GetInstance()->GetPrimarySystemTray(); | |
106 return tray ? static_cast<ash::StatusAreaWidgetDelegate*>( | |
107 tray->GetWidget()->GetContentsView()) | |
108 : nullptr; | |
109 } | |
110 | |
99 } // namespace | 111 } // namespace |
100 | 112 |
101 namespace chromeos { | 113 namespace chromeos { |
102 | 114 |
103 // static | 115 // static |
104 const char WebUILoginView::kViewClassName[] = | 116 const char WebUILoginView::kViewClassName[] = |
105 "browser/chromeos/login/WebUILoginView"; | 117 "browser/chromeos/login/WebUILoginView"; |
106 | 118 |
119 // WebUILoginView::CycleFocusTraversable --------------------------------------- | |
120 class WebUILoginView::CycleFocusTraversable : public views::FocusTraversable { | |
121 public: | |
122 explicit CycleFocusTraversable(WebUILoginView* webui_login_view) | |
123 : cycle_focus_search_(webui_login_view, true, false) {} | |
124 ~CycleFocusTraversable() override {} | |
125 | |
126 // views::FocusTraversable | |
127 views::FocusSearch* GetFocusSearch() override { return &cycle_focus_search_; } | |
128 | |
129 views::FocusTraversable* GetFocusTraversableParent() override { | |
130 return nullptr; | |
131 } | |
132 | |
133 views::View* GetFocusTraversableParentView() override { return nullptr; } | |
134 | |
135 private: | |
136 views::FocusSearch cycle_focus_search_; | |
137 | |
138 DISALLOW_COPY_AND_ASSIGN(CycleFocusTraversable); | |
139 }; | |
140 | |
141 // WebUILoginView::StatusAreaFocusTraversable ---------------------------------- | |
142 class WebUILoginView::StatusAreaFocusTraversable | |
143 : public views::FocusTraversable { | |
144 public: | |
145 StatusAreaFocusTraversable( | |
146 ash::StatusAreaWidgetDelegate* status_area_widget_delegate, | |
147 WebUILoginView* webui_login_view) | |
148 : webui_login_view_(webui_login_view), | |
149 status_area_focus_search_(status_area_widget_delegate, false, false) {} | |
150 ~StatusAreaFocusTraversable() override {} | |
151 | |
152 // views::FocusTraversable | |
153 views::FocusSearch* GetFocusSearch() override { | |
154 return &status_area_focus_search_; | |
155 } | |
156 | |
157 views::FocusTraversable* GetFocusTraversableParent() override { | |
158 return webui_login_view_->cycle_focus_traversable_.get(); | |
159 } | |
160 | |
161 views::View* GetFocusTraversableParentView() override { | |
162 return webui_login_view_->status_area_widget_host_; | |
163 } | |
164 | |
165 private: | |
166 WebUILoginView* const webui_login_view_; | |
167 views::FocusSearch status_area_focus_search_; | |
168 | |
169 DISALLOW_COPY_AND_ASSIGN(StatusAreaFocusTraversable); | |
170 }; | |
171 | |
107 // WebUILoginView public: ------------------------------------------------------ | 172 // WebUILoginView public: ------------------------------------------------------ |
108 | 173 |
109 WebUILoginView::WebUILoginView() | 174 WebUILoginView::WebUILoginView() |
110 : webui_login_(NULL), | 175 : webui_login_(NULL), |
111 is_hidden_(false), | 176 is_hidden_(false), |
112 webui_visible_(false), | 177 webui_visible_(false), |
113 should_emit_login_prompt_visible_(true), | 178 should_emit_login_prompt_visible_(true), |
114 forward_keyboard_event_(true) { | 179 forward_keyboard_event_(true) { |
115 registrar_.Add(this, | 180 registrar_.Add(this, |
116 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, | 181 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
162 AddAccelerator(i->first); | 227 AddAccelerator(i->first); |
163 } | 228 } |
164 | 229 |
165 WebUILoginView::~WebUILoginView() { | 230 WebUILoginView::~WebUILoginView() { |
166 FOR_EACH_OBSERVER(web_modal::ModalDialogHostObserver, | 231 FOR_EACH_OBSERVER(web_modal::ModalDialogHostObserver, |
167 observer_list_, | 232 observer_list_, |
168 OnHostDestroying()); | 233 OnHostDestroying()); |
169 | 234 |
170 if (!chrome::IsRunningInMash() && | 235 if (!chrome::IsRunningInMash() && |
171 ash::Shell::GetInstance()->HasPrimaryStatusArea()) { | 236 ash::Shell::GetInstance()->HasPrimaryStatusArea()) { |
172 ash::Shell::GetInstance()->GetPrimarySystemTray()-> | 237 views::Widget* tray_widget = |
173 SetNextFocusableView(NULL); | 238 ash::Shell::GetInstance()->GetPrimarySystemTray()->GetWidget(); |
239 ash::StatusAreaWidgetDelegate* status_area_widget_delegate = | |
240 static_cast<ash::StatusAreaWidgetDelegate*>( | |
241 tray_widget->GetContentsView()); | |
242 status_area_widget_delegate->set_custom_focus_traversable(nullptr); | |
243 status_area_widget_delegate->set_default_last_focusable_child(false); | |
174 } else { | 244 } else { |
175 NOTIMPLEMENTED(); | 245 NOTIMPLEMENTED(); |
176 } | 246 } |
177 } | 247 } |
178 | 248 |
179 void WebUILoginView::Init() { | 249 void WebUILoginView::Init() { |
180 Profile* signin_profile = ProfileHelper::GetSigninProfile(); | 250 Profile* signin_profile = ProfileHelper::GetSigninProfile(); |
181 webui_login_ = new views::WebView(signin_profile); | 251 webui_login_ = new views::WebView(signin_profile); |
182 webui_login_->set_allow_accelerators(true); | 252 webui_login_->set_allow_accelerators(true); |
183 AddChildView(webui_login_); | 253 AddChildView(webui_login_); |
(...skipping 15 matching lines...) Expand all Loading... | |
199 WebContentsModalDialogManager::FromWebContents(web_contents)-> | 269 WebContentsModalDialogManager::FromWebContents(web_contents)-> |
200 SetDelegate(this); | 270 SetDelegate(this); |
201 | 271 |
202 web_contents->SetDelegate(this); | 272 web_contents->SetDelegate(this); |
203 extensions::SetViewType(web_contents, extensions::VIEW_TYPE_COMPONENT); | 273 extensions::SetViewType(web_contents, extensions::VIEW_TYPE_COMPONENT); |
204 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents( | 274 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents( |
205 web_contents); | 275 web_contents); |
206 content::RendererPreferences* prefs = web_contents->GetMutableRendererPrefs(); | 276 content::RendererPreferences* prefs = web_contents->GetMutableRendererPrefs(); |
207 renderer_preferences_util::UpdateFromSystemSettings( | 277 renderer_preferences_util::UpdateFromSystemSettings( |
208 prefs, signin_profile, web_contents); | 278 prefs, signin_profile, web_contents); |
279 | |
280 status_area_widget_host_ = new views::View; | |
281 AddChildView(status_area_widget_host_); | |
209 } | 282 } |
210 | 283 |
211 const char* WebUILoginView::GetClassName() const { | 284 const char* WebUILoginView::GetClassName() const { |
212 return kViewClassName; | 285 return kViewClassName; |
213 } | 286 } |
214 | 287 |
215 void WebUILoginView::RequestFocus() { | 288 void WebUILoginView::RequestFocus() { |
216 webui_login_->RequestFocus(); | 289 webui_login_->RequestFocus(); |
217 } | 290 } |
218 | 291 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
274 webui_login_->LoadInitialURL(url); | 347 webui_login_->LoadInitialURL(url); |
275 webui_login_->RequestFocus(); | 348 webui_login_->RequestFocus(); |
276 | 349 |
277 // TODO(nkostylev): Use WebContentsObserver::RenderViewCreated to track | 350 // TODO(nkostylev): Use WebContentsObserver::RenderViewCreated to track |
278 // when RenderView is created. | 351 // when RenderView is created. |
279 GetWebContents() | 352 GetWebContents() |
280 ->GetRenderViewHost() | 353 ->GetRenderViewHost() |
281 ->GetWidget() | 354 ->GetWidget() |
282 ->GetView() | 355 ->GetView() |
283 ->SetBackgroundColor(SK_ColorTRANSPARENT); | 356 ->SetBackgroundColor(SK_ColorTRANSPARENT); |
357 | |
358 ash::StatusAreaWidgetDelegate* status_area_widget_delegate = | |
359 GetStatusAreaWidgetDelegate(); | |
360 DCHECK(status_area_widget_delegate); | |
361 cycle_focus_traversable_.reset(new CycleFocusTraversable(this)); | |
362 status_area_focus_traversable_.reset( | |
363 new StatusAreaFocusTraversable(status_area_widget_delegate, this)); | |
364 status_area_widget_delegate->set_custom_focus_traversable( | |
365 status_area_focus_traversable_.get()); | |
284 } | 366 } |
285 | 367 |
286 content::WebUI* WebUILoginView::GetWebUI() { | 368 content::WebUI* WebUILoginView::GetWebUI() { |
287 return webui_login_->web_contents()->GetWebUI(); | 369 return webui_login_->web_contents()->GetWebUI(); |
288 } | 370 } |
289 | 371 |
290 content::WebContents* WebUILoginView::GetWebContents() { | 372 content::WebContents* WebUILoginView::GetWebContents() { |
291 return webui_login_->web_contents(); | 373 return webui_login_->web_contents(); |
292 } | 374 } |
293 | 375 |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
428 // In case of blocked UI (ex.: sign in is in progress) | 510 // In case of blocked UI (ex.: sign in is in progress) |
429 // we should not process focus change events. | 511 // we should not process focus change events. |
430 if (!forward_keyboard_event_) | 512 if (!forward_keyboard_event_) |
431 return false; | 513 return false; |
432 | 514 |
433 // Focus is accepted, but the Ash system tray is not available in Mash, so | 515 // Focus is accepted, but the Ash system tray is not available in Mash, so |
434 // exit early. | 516 // exit early. |
435 if (chrome::IsRunningInMash()) | 517 if (chrome::IsRunningInMash()) |
436 return true; | 518 return true; |
437 | 519 |
438 ash::SystemTray* tray = ash::Shell::GetInstance()->GetPrimarySystemTray(); | 520 ash::StatusAreaWidgetDelegate* status_area_widget_delegate = |
439 if (tray && tray->GetWidget()->IsVisible()) { | 521 GetStatusAreaWidgetDelegate(); |
440 tray->SetNextFocusableView(this); | 522 if (status_area_widget_delegate && status_area_widget_delegate->visible()) { |
xiyuan
2016/09/13 21:56:46
status_area_widget_delegate->visible() is not the
Qiang(Joe) Xu
2016/09/13 22:07:21
done. Thanks, good to know this.
| |
523 status_area_widget_delegate->set_default_last_focusable_child(reverse); | |
441 ash::WmShell::Get()->focus_cycler()->RotateFocus( | 524 ash::WmShell::Get()->focus_cycler()->RotateFocus( |
442 reverse ? ash::FocusCycler::BACKWARD : ash::FocusCycler::FORWARD); | 525 reverse ? ash::FocusCycler::BACKWARD : ash::FocusCycler::FORWARD); |
443 } | 526 } |
444 | 527 |
445 return true; | 528 return true; |
446 } | 529 } |
447 | 530 |
448 void WebUILoginView::RequestMediaAccessPermission( | 531 void WebUILoginView::RequestMediaAccessPermission( |
449 WebContents* web_contents, | 532 WebContents* web_contents, |
450 const content::MediaStreamRequest& request, | 533 const content::MediaStreamRequest& request, |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
518 if (should_emit_login_prompt_visible_) { | 601 if (should_emit_login_prompt_visible_) { |
519 VLOG(1) << "Login WebUI >> login-prompt-visible"; | 602 VLOG(1) << "Login WebUI >> login-prompt-visible"; |
520 chromeos::DBusThreadManager::Get()->GetSessionManagerClient()-> | 603 chromeos::DBusThreadManager::Get()->GetSessionManagerClient()-> |
521 EmitLoginPromptVisible(); | 604 EmitLoginPromptVisible(); |
522 } | 605 } |
523 | 606 |
524 webui_visible_ = true; | 607 webui_visible_ = true; |
525 } | 608 } |
526 | 609 |
527 } // namespace chromeos | 610 } // namespace chromeos |
OLD | NEW |