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

Side by Side Diff: chrome/browser/chromeos/login/webui_login_view.cc

Issue 6973029: Integrate WebUI Login with cros. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Updated code in response to review comments Created 9 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/chromeos/login/webui_login_view.h"
6
7 #include <vector>
8
9 #include "base/logging.h"
10 #include "chrome/browser/chromeos/login/helper.h"
11 #include "chrome/browser/chromeos/login/login_utils.h"
12 #include "chrome/browser/chromeos/login/proxy_settings_dialog.h"
13 #include "chrome/browser/chromeos/status/clock_menu_button.h"
14 #include "chrome/browser/chromeos/status/input_method_menu_button.h"
15 #include "chrome/browser/chromeos/status/network_menu_button.h"
16 #include "chrome/browser/chromeos/status/status_area_view.h"
17 #include "chrome/browser/chromeos/wm_ipc.h"
18 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/profiles/profile_manager.h"
20 #include "chrome/browser/renderer_host/render_widget_host_view_views.h"
21 #include "chrome/browser/ui/touch/frame/keyboard_container_view.h"
22 #include "chrome/browser/ui/views/dom_view.h"
23 #include "chrome/browser/ui/views/tab_contents/tab_contents_view_touch.h"
24 #include "content/browser/renderer_host/render_view_host.h"
25 #include "content/browser/tab_contents/tab_contents.h"
26 #include "content/common/notification_service.h"
27 #include "googleurl/src/gurl.h"
28 #include "ui/base/x/x11_util.h"
29 #include "ui/gfx/transform.h"
30 #include "views/controls/textfield/textfield.h"
31 #include "views/widget/widget.h"
32
33 // TODO(rharrison): Modify this class to support both touch and non-touch
34
35 namespace {
36
37 const int kKeyboardHeight = 300;
38 const int kKeyboardSlideDuration = 500; // In milliseconds
39
40 PropertyAccessor<bool>* GetFocusedStateAccessor() {
41 static PropertyAccessor<bool> state;
42 return &state;
43 }
44
45 bool TabContentsHasFocus(const TabContents* contents) {
46 views::View* view = static_cast<TabContentsViewTouch*>(contents->view());
47 return view->Contains(view->GetFocusManager()->GetFocusedView());
48 }
49
50 } // namespace
51
52 namespace chromeos {
53
54 // static
55 const char WebUILoginView::kViewClassName[] =
56 "browser/chromeos/login/WebUILoginView";
57
58 // WebUILoginView public: ------------------------------------------------------
59
60 WebUILoginView::WebUILoginView()
61 : profile_(NULL),
62 status_area_(NULL),
63 did_paint_(false),
64 webui_login_(NULL),
65 keyboard_showing_(false),
66 focus_listener_added_(false),
67 keyboard_(NULL) {
68 }
69
70 void WebUILoginView::Init(const GURL& login_url) {
71 CHECK(!login_url.is_empty());
72 profile_ = ProfileManager::GetDefaultProfile();
73 if (!profile_->GetExtensionService()) {
74 if (profile_->IsOffTheRecord())
75 profile_ = profile_->GetOriginalProfile();
76 profile_->InitExtensions(false);
77 }
78
79 webui_login_ = new DOMView();
80 AddChildView(webui_login_);
81 webui_login_->Init(profile_, NULL);
82 webui_login_->LoadURL(login_url);
83 webui_login_->SetVisible(true);
84
85 InitStatusArea();
86
87 registrar_.Add(this,
88 NotificationType::FOCUS_CHANGED_IN_PAGE,
89 NotificationService::AllSources());
90 registrar_.Add(this,
91 NotificationType::TAB_CONTENTS_DESTROYED,
92 NotificationService::AllSources());
93 }
94
95 // static
96 views::Widget* WebUILoginView::CreateWindowContainingView(
97 const gfx::Rect& bounds,
98 const GURL& login_url,
99 WebUILoginView** view) {
100 ResetXCursor();
101
102 views::Widget* window = new views::Widget;
103 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
104 params.bounds = bounds;
105 window->Init(params);
106 *view = new WebUILoginView();
107 (*view)->Init(login_url);
108
109 window->SetContentsView(*view);
110
111 (*view)->UpdateWindowType();
112
113 // This keeps the window from flashing at startup.
114 GdkWindow* gdk_window = window->GetNativeView()->window;
115 gdk_window_set_back_pixmap(gdk_window, NULL, false);
116
117 return window;
118 }
119
120 std::string WebUILoginView::GetClassName() const {
121 return kViewClassName;
122 }
123
124 gfx::NativeWindow WebUILoginView::GetNativeWindow() const {
125 return GetWidget()->GetNativeWindow();
126 }
127
128 void WebUILoginView::FocusWillChange(views::View* focused_before,
129 views::View* focused_now) {
130 VirtualKeyboardType before = DecideKeyboardStateForView(focused_before);
131 VirtualKeyboardType now = DecideKeyboardStateForView(focused_now);
132 if (before != now) {
133 // TODO(varunjain): support other types of keyboard.
134 UpdateKeyboardAndLayout(now == GENERIC);
135 }
136 }
137
138 // WebUILoginView protected: ---------------------------------------------------
139
140 void WebUILoginView::OnPaint(gfx::Canvas* canvas) {
141 views::View::OnPaint(canvas);
142 if (!did_paint_) {
143 did_paint_ = true;
144 UpdateWindowType();
145 }
146 }
147
148 void WebUILoginView::Layout() {
149 const int kCornerPadding = 5;
150 gfx::Size status_area_size = status_area_->GetPreferredSize();
151 status_area_->SetBounds(
152 width() - status_area_size.width() - kCornerPadding,
153 kCornerPadding,
154 status_area_size.width(),
155 status_area_size.height());
156
157 if (webui_login_)
158 webui_login_->SetBoundsRect(bounds());
159
160 // TODO(rharrison): Hide touch specific code behind TOUCH_UI defines
161 if (!keyboard_)
162 return;
163
164 keyboard_->SetVisible(keyboard_showing_);
165 gfx::Rect keyboard_bounds = bounds();
166 keyboard_bounds.set_y(keyboard_bounds.height() - kKeyboardHeight);
167 keyboard_bounds.set_height(kKeyboardHeight);
168 keyboard_->SetBoundsRect(keyboard_bounds);
169 }
170
171 void WebUILoginView::ChildPreferredSizeChanged(View* child) {
172 Layout();
173 SchedulePaint();
174 }
175
176 Profile* WebUILoginView::GetProfile() const {
177 return NULL;
178 }
179
180 void WebUILoginView::ExecuteBrowserCommand(int id) const {
181 }
182
183 bool WebUILoginView::ShouldOpenButtonOptions(
184 const views::View* button_view) const {
185 if (button_view == status_area_->network_view())
186 return true;
187
188 if (button_view == status_area_->clock_view() ||
189 button_view == status_area_->input_method_view())
190 return false;
191
192 return true;
193 }
194
195 void WebUILoginView::OpenButtonOptions(const views::View* button_view) {
196 if (button_view == status_area_->network_view()) {
197 if (proxy_settings_dialog_.get() == NULL) {
198 proxy_settings_dialog_.reset(new ProxySettingsDialog(
199 this, GetNativeWindow()));
200 }
201 proxy_settings_dialog_->Show();
202 }
203 }
204
205 StatusAreaHost::ScreenMode WebUILoginView::GetScreenMode() const {
206 return kLoginMode;
207 }
208
209 StatusAreaHost::TextStyle WebUILoginView::GetTextStyle() const {
210 return kWhitePlain;
211 }
212
213 void WebUILoginView::OnDialogClosed() {
214 }
215
216 void WebUILoginView::OnLocaleChanged() {
217 // Proxy settings dialog contains localized strings.
218 proxy_settings_dialog_.reset();
219 SchedulePaint();
220 }
221
222 // WebUILoginView private: -----------------------------------------------------
223
224 void WebUILoginView::InitStatusArea() {
225 DCHECK(status_area_ == NULL);
226 status_area_ = new StatusAreaView(this);
227 status_area_->Init();
228 AddChildView(status_area_);
229 }
230
231 void WebUILoginView::UpdateWindowType() {
232 std::vector<int> params;
233 WmIpc::instance()->SetWindowType(
234 GTK_WIDGET(GetNativeWindow()),
235 WM_IPC_WINDOW_LOGIN_WEBUI,
236 &params);
237 }
238
239 void WebUILoginView::InitVirtualKeyboard() {
240 if (keyboard_)
241 return;
242
243 keyboard_ = new KeyboardContainerView(profile_, NULL);
244 keyboard_->SetVisible(false);
245 AddChildView(keyboard_);
246 }
247
248 void WebUILoginView::UpdateKeyboardAndLayout(bool should_show_keyboard) {
249 if (should_show_keyboard)
250 InitVirtualKeyboard();
251
252 if (should_show_keyboard == keyboard_showing_)
253 return;
254
255 DCHECK(keyboard_);
256
257 keyboard_showing_ = should_show_keyboard;
258 Layout();
259 }
260
261 WebUILoginView::VirtualKeyboardType
262 WebUILoginView::DecideKeyboardStateForView(views::View* view) {
263 if (!view)
264 return NONE;
265
266 std::string cname = view->GetClassName();
267 if (cname == views::Textfield::kViewClassName) {
268 return GENERIC;
269 } else if (cname == RenderWidgetHostViewViews::kViewClassName) {
270 TabContents* contents = webui_login_->tab_contents();
271 bool* editable = contents ? GetFocusedStateAccessor()->GetProperty(
272 contents->property_bag()) : NULL;
273 if (editable && *editable)
274 return GENERIC;
275 }
276 return NONE;
277 }
278
279 void WebUILoginView::Observe(NotificationType type,
280 const NotificationSource& source,
281 const NotificationDetails& details) {
282 if (type == NotificationType::FOCUS_CHANGED_IN_PAGE) {
283 // Only modify the keyboard state if the currently active tab sent the
284 // notification.
285 const TabContents* current_tab = webui_login_->tab_contents();
286 TabContents* source_tab = Source<TabContents>(source).ptr();
287 const bool editable = *Details<const bool>(details).ptr();
288
289 if (current_tab == source_tab && TabContentsHasFocus(source_tab))
290 UpdateKeyboardAndLayout(editable);
291
292 // Save the state of the focused field so that the keyboard visibility
293 // can be determined after tab switching.
294 GetFocusedStateAccessor()->SetProperty(
295 source_tab->property_bag(), editable);
296 } else if (type == NotificationType::TAB_CONTENTS_DESTROYED) {
297 GetFocusedStateAccessor()->DeleteProperty(
298 Source<TabContents>(source).ptr()->property_bag());
299 }
300 }
301
302 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698