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

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

Issue 7302015: A keyboard widget that manages itself (the animation and all that). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 years, 5 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
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 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/touch_login_view.h" 5 #include "chrome/browser/chromeos/login/touch_login_view.h"
6 6
7 #include "chrome/browser/renderer_host/render_widget_host_view_views.h" 7 #include "chrome/browser/ui/touch/keyboard/keyboard_manager.h"
8 #include "chrome/browser/ui/touch/frame/keyboard_container_view.h"
9 #include "chrome/browser/ui/views/tab_contents/tab_contents_view_touch.h"
10 #include "chrome/browser/ui/views/dom_view.h"
11 #include "content/browser/tab_contents/tab_contents.h"
12 #include "content/common/notification_service.h"
13 #include "ui/base/animation/slide_animation.h"
14 #include "ui/gfx/transform.h"
15 #include "views/controls/textfield/textfield.h"
16 #include "views/widget/widget.h"
17
18 namespace {
19
20 const char kViewClassName[] = "browser/chromeos/login/TouchLoginView";
21 const int kDefaultKeyboardHeight = 300;
22 const int kKeyboardSlideDuration = 300; // In milliseconds
23
24 PropertyAccessor<bool>* GetFocusedStateAccessor() {
25 static PropertyAccessor<bool> state;
26 return &state;
27 }
28
29 bool TabContentsHasFocus(const TabContents* contents) {
30 views::View* view = static_cast<TabContentsViewTouch*>(contents->view());
31 return view->Contains(view->GetFocusManager()->GetFocusedView());
32 }
33
34 } // namespace
35 8
36 namespace chromeos { 9 namespace chromeos {
37 10
38 // TouchLoginView public: ------------------------------------------------------ 11 // TouchLoginView public: ------------------------------------------------------
39 12
40 TouchLoginView::TouchLoginView() 13 TouchLoginView::TouchLoginView()
41 : WebUILoginView(), 14 : WebUILoginView() {
42 keyboard_showing_(false), 15 KeyboardManager::GetInstance();
sadrul 2011/07/05 06:03:38 Perhaps this can just be done in WebUILoginView wi
bryeung 2011/07/05 14:23:13 That sounds better to me: seems silly to be subcla
43 keyboard_height_(kDefaultKeyboardHeight),
44 focus_listener_added_(false),
45 keyboard_(NULL) {
46 } 16 }
47 17
48 TouchLoginView::~TouchLoginView() { 18 TouchLoginView::~TouchLoginView() {
49 } 19 }
50 20
51 void TouchLoginView::Init() {
52 WebUILoginView::Init();
53 InitVirtualKeyboard();
54
55 registrar_.Add(this,
56 NotificationType::FOCUS_CHANGED_IN_PAGE,
57 NotificationService::AllSources());
58 registrar_.Add(this,
59 NotificationType::TAB_CONTENTS_DESTROYED,
60 NotificationService::AllSources());
61 }
62
63 std::string TouchLoginView::GetClassName() const {
64 return kViewClassName;
65 }
66
67 void TouchLoginView::FocusWillChange(views::View* focused_before,
68 views::View* focused_now) {
69 VirtualKeyboardType before = DecideKeyboardStateForView(focused_before);
70 VirtualKeyboardType now = DecideKeyboardStateForView(focused_now);
71 if (before != now) {
72 // TODO(varunjain): support other types of keyboard.
73 UpdateKeyboardAndLayout(now == GENERIC);
74 }
75 }
76
77 // TouchLoginView protected: ---------------------------------------------------
78
79 void TouchLoginView::Layout() {
80 WebUILoginView::Layout();
81 if (!keyboard_)
82 return;
83
84 // We are not resizing the DOMView here, so the keyboard is going to occlude
85 // the login screen partially. It is the responsibility of the UX layer to
86 // handle this.
87
88 // Lastly layout the keyboard
89 bool display_keyboard = (keyboard_showing_ || animation_->is_animating());
90 keyboard_->SetVisible(display_keyboard);
91 gfx::Rect keyboard_bounds = bounds();
92 int keyboard_height = display_keyboard ? keyboard_height_ : 0;
93 keyboard_bounds.set_y(keyboard_bounds.height() - keyboard_height);
94 keyboard_bounds.set_height(keyboard_height);
95 keyboard_->SetBoundsRect(keyboard_bounds);
96 }
97
98 // TouchLoginView private: -----------------------------------------------------
99
100 void TouchLoginView::InitVirtualKeyboard() {
101 keyboard_ = new KeyboardContainerView(profile_, NULL);
102 keyboard_->SetVisible(false);
103 AddChildView(keyboard_);
104
105 animation_.reset(new ui::SlideAnimation(this));
106 animation_->SetTweenType(ui::Tween::LINEAR);
107 animation_->SetSlideDuration(kKeyboardSlideDuration);
108 }
109
110 void TouchLoginView::UpdateKeyboardAndLayout(bool should_show_keyboard) {
111 DCHECK(keyboard_);
112 if (should_show_keyboard == keyboard_showing_)
113 return;
114 keyboard_showing_ = should_show_keyboard;
115 if (keyboard_showing_) {
116 ui::Transform transform;
117 transform.SetTranslateY(-keyboard_height_);
118 keyboard_->SetTransform(transform);
119 Layout();
120 animation_->Show();
121 } else {
122 ui::Transform transform;
123 keyboard_->SetTransform(transform);
124 animation_->Hide();
125 Layout();
126 }
127 }
128
129 TouchLoginView::VirtualKeyboardType
130 TouchLoginView::DecideKeyboardStateForView(views::View* view) {
131 if (!view)
132 return NONE;
133
134 std::string cname = view->GetClassName();
135 if (cname == views::Textfield::kViewClassName) {
136 return GENERIC;
137 } else if (cname == RenderWidgetHostViewViews::kViewClassName) {
138 TabContents* contents = webui_login_->tab_contents();
139 bool* editable = contents ? GetFocusedStateAccessor()->GetProperty(
140 contents->property_bag()) : NULL;
141 if (editable && *editable)
142 return GENERIC;
143 }
144 return NONE;
145 }
146
147 void TouchLoginView::Observe(NotificationType type,
148 const NotificationSource& source,
149 const NotificationDetails& details) {
150 if (type == NotificationType::FOCUS_CHANGED_IN_PAGE) {
151 // Only modify the keyboard state if the currently active tab sent the
152 // notification.
153 const TabContents* current_tab = webui_login_->tab_contents();
154 TabContents* source_tab = Source<TabContents>(source).ptr();
155 const bool editable = *Details<const bool>(details).ptr();
156
157 if (current_tab == source_tab && TabContentsHasFocus(source_tab))
158 UpdateKeyboardAndLayout(editable);
159
160 // Save the state of the focused field so that the keyboard visibility
161 // can be determined after tab switching.
162 GetFocusedStateAccessor()->SetProperty(
163 source_tab->property_bag(), editable);
164 } else if (type == NotificationType::TAB_CONTENTS_DESTROYED) {
165 GetFocusedStateAccessor()->DeleteProperty(
166 Source<TabContents>(source).ptr()->property_bag());
167 }
168 }
169
170 // ui::AnimationDelegate implementation ----------------------------------------
171
172 void TouchLoginView::AnimationProgressed(const ui::Animation* anim) {
173 ui::Transform transform;
174 transform.SetTranslateY(
175 ui::Tween::ValueBetween(anim->GetCurrentValue(), keyboard_height_, 0));
176 keyboard_->SetTransform(transform);
177 }
178
179 void TouchLoginView::AnimationEnded(const ui::Animation* animation) {
180 if (keyboard_showing_) {
181 Layout();
182 } else {
183 // Notify the keyboard that it is hidden now.
184 keyboard_->SetVisible(false);
185 }
186 }
187
188 } // namespace chromeos 21 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698