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

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

Powered by Google App Engine
This is Rietveld 408576698