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

Side by Side Diff: chrome/browser/ui/touch/frame/touch_browser_frame_view.cc

Issue 7058046: Adjust virtual keyboard size base on input method candidates. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Update Created 9 years, 6 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/ui/touch/frame/touch_browser_frame_view.h" 5 #include "chrome/browser/ui/touch/frame/touch_browser_frame_view.h"
6 6
7 #include "chrome/browser/profiles/profile.h" 7 #include "chrome/browser/profiles/profile.h"
8 #include "chrome/browser/renderer_host/render_widget_host_view_views.h" 8 #include "chrome/browser/renderer_host/render_widget_host_view_views.h"
9 #include "chrome/browser/tabs/tab_strip_model.h" 9 #include "chrome/browser/tabs/tab_strip_model.h"
10 #include "chrome/browser/ui/browser.h" 10 #include "chrome/browser/ui/browser.h"
(...skipping 10 matching lines...) Expand all
21 #include "content/common/view_messages.h" 21 #include "content/common/view_messages.h"
22 #include "ui/base/animation/slide_animation.h" 22 #include "ui/base/animation/slide_animation.h"
23 #include "ui/gfx/rect.h" 23 #include "ui/gfx/rect.h"
24 #include "ui/gfx/transform.h" 24 #include "ui/gfx/transform.h"
25 #include "views/controls/button/image_button.h" 25 #include "views/controls/button/image_button.h"
26 #include "views/controls/textfield/textfield.h" 26 #include "views/controls/textfield/textfield.h"
27 #include "views/focus/focus_manager.h" 27 #include "views/focus/focus_manager.h"
28 28
29 namespace { 29 namespace {
30 30
31 const int kKeyboardHeight = 360; 31 const int kKeyboardHeight = 300;
bryeung 2011/06/03 19:14:52 please rename to kDefaultKeyboardHeight
Peng 2011/06/03 22:22:10 Done.
32 const int kKeyboardSlideDuration = 500; // In milliseconds 32 const int kKeyboardSlideDuration = 500; // In milliseconds
33 33
34 PropertyAccessor<bool>* GetFocusedStateAccessor() { 34 PropertyAccessor<bool>* GetFocusedStateAccessor() {
35 static PropertyAccessor<bool> state; 35 static PropertyAccessor<bool> state;
36 return &state; 36 return &state;
37 } 37 }
38 38
39 bool TabContentsHasFocus(const TabContents* contents) { 39 bool TabContentsHasFocus(const TabContents* contents) {
40 views::View* view = static_cast<TabContentsViewTouch*>(contents->view()); 40 views::View* view = static_cast<TabContentsViewTouch*>(contents->view());
41 return view->Contains(view->GetFocusManager()->GetFocusedView()); 41 return view->Contains(view->GetFocusManager()->GetFocusedView());
42 } 42 }
43 43
44 } // namespace 44 } // namespace
45 45
46 // static 46 // static
47 const char TouchBrowserFrameView::kViewClassName[] = 47 const char TouchBrowserFrameView::kViewClassName[] =
48 "browser/ui/touch/frame/TouchBrowserFrameView"; 48 "browser/ui/touch/frame/TouchBrowserFrameView";
49 49
50 /////////////////////////////////////////////////////////////////////////////// 50 ///////////////////////////////////////////////////////////////////////////////
51 // TouchBrowserFrameView, public: 51 // TouchBrowserFrameView, public:
52 52
53 TouchBrowserFrameView::TouchBrowserFrameView(BrowserFrame* frame, 53 TouchBrowserFrameView::TouchBrowserFrameView(BrowserFrame* frame,
54 BrowserView* browser_view) 54 BrowserView* browser_view)
55 : OpaqueBrowserFrameView(frame, browser_view), 55 : OpaqueBrowserFrameView(frame, browser_view),
56 keyboard_showing_(false), 56 keyboard_showing_(false),
57 keyboard_height_(kKeyboardHeight),
57 focus_listener_added_(false), 58 focus_listener_added_(false),
58 keyboard_(NULL) { 59 keyboard_(NULL) {
59 registrar_.Add(this, 60 registrar_.Add(this,
60 NotificationType::NAV_ENTRY_COMMITTED, 61 NotificationType::NAV_ENTRY_COMMITTED,
61 NotificationService::AllSources()); 62 NotificationService::AllSources());
62 registrar_.Add(this, 63 registrar_.Add(this,
63 NotificationType::FOCUS_CHANGED_IN_PAGE, 64 NotificationType::FOCUS_CHANGED_IN_PAGE,
64 NotificationService::AllSources()); 65 NotificationService::AllSources());
65 registrar_.Add(this, 66 registrar_.Add(this,
66 NotificationType::TAB_CONTENTS_DESTROYED, 67 NotificationType::TAB_CONTENTS_DESTROYED,
67 NotificationService::AllSources()); 68 NotificationService::AllSources());
68 registrar_.Add(this, 69 registrar_.Add(this,
69 NotificationType::HIDE_KEYBOARD_INVOKED, 70 NotificationType::HIDE_KEYBOARD_INVOKED,
70 NotificationService::AllSources()); 71 NotificationService::AllSources());
72 registrar_.Add(this,
73 NotificationType::SET_KEYBOARD_HEIGHT_INVOKED,
74 NotificationService::AllSources());
71 75
72 browser_view->browser()->tabstrip_model()->AddObserver(this); 76 browser_view->browser()->tabstrip_model()->AddObserver(this);
73 77
74 animation_.reset(new ui::SlideAnimation(this)); 78 animation_.reset(new ui::SlideAnimation(this));
75 animation_->SetTweenType(ui::Tween::LINEAR); 79 animation_->SetTweenType(ui::Tween::LINEAR);
76 animation_->SetSlideDuration(kKeyboardSlideDuration); 80 animation_->SetSlideDuration(kKeyboardSlideDuration);
77 } 81 }
78 82
79 TouchBrowserFrameView::~TouchBrowserFrameView() { 83 TouchBrowserFrameView::~TouchBrowserFrameView() {
80 browser_view()->browser()->tabstrip_model()->RemoveObserver(this); 84 browser_view()->browser()->tabstrip_model()->RemoveObserver(this);
81 } 85 }
82 86
83 std::string TouchBrowserFrameView::GetClassName() const { 87 std::string TouchBrowserFrameView::GetClassName() const {
84 return kViewClassName; 88 return kViewClassName;
85 } 89 }
86 90
87 void TouchBrowserFrameView::Layout() { 91 void TouchBrowserFrameView::Layout() {
88 OpaqueBrowserFrameView::Layout(); 92 OpaqueBrowserFrameView::Layout();
89 93
90 if (!keyboard_) 94 if (!keyboard_)
91 return; 95 return;
92 96
93 keyboard_->SetVisible(keyboard_showing_ || animation_->is_animating()); 97 keyboard_->SetVisible(keyboard_showing_ || animation_->is_animating());
94 gfx::Rect bounds = GetBoundsForReservedArea(); 98 gfx::Rect bounds = GetBoundsForReservedArea();
95 if (animation_->is_animating() && !keyboard_showing_) { 99 if (animation_->is_animating() && !keyboard_showing_) {
96 // The keyboard is in the process of hiding. So pretend it still has the 100 // The keyboard is in the process of hiding. So pretend it still has the
97 // same bounds as when the keyboard is visible. But 101 // same bounds as when the keyboard is visible. But
98 // |GetBoundsForReservedArea| should not take this into account so that the 102 // |GetBoundsForReservedArea| should not take this into account so that the
99 // render view gets the entire area to relayout itself. 103 // render view gets the entire area to relayout itself.
100 bounds.set_y(bounds.y() - kKeyboardHeight); 104 bounds.set_y(bounds.y() - keyboard_height_);
101 bounds.set_height(kKeyboardHeight); 105 bounds.set_height(keyboard_height_);
102 } 106 }
103 keyboard_->SetBoundsRect(bounds); 107 keyboard_->SetBoundsRect(bounds);
104 } 108 }
105 109
106 void TouchBrowserFrameView::FocusWillChange(views::View* focused_before, 110 void TouchBrowserFrameView::FocusWillChange(views::View* focused_before,
107 views::View* focused_now) { 111 views::View* focused_now) {
108 VirtualKeyboardType before = DecideKeyboardStateForView(focused_before); 112 VirtualKeyboardType before = DecideKeyboardStateForView(focused_before);
109 VirtualKeyboardType now = DecideKeyboardStateForView(focused_now); 113 VirtualKeyboardType now = DecideKeyboardStateForView(focused_now);
110 if (before != now) { 114 if (before != now) {
111 // TODO(varunjain): support other types of keyboard. 115 // TODO(varunjain): support other types of keyboard.
112 UpdateKeyboardAndLayout(now == GENERIC); 116 UpdateKeyboardAndLayout(now == GENERIC);
113 } 117 }
114 } 118 }
115 119
116 /////////////////////////////////////////////////////////////////////////////// 120 ///////////////////////////////////////////////////////////////////////////////
117 // TouchBrowserFrameView, protected: 121 // TouchBrowserFrameView, protected:
118 int TouchBrowserFrameView::GetReservedHeight() const { 122 int TouchBrowserFrameView::GetReservedHeight() const {
119 return keyboard_showing_ ? kKeyboardHeight : 0; 123 return keyboard_showing_ ? keyboard_height_ : 0;
120 } 124 }
121 125
122 void TouchBrowserFrameView::ViewHierarchyChanged(bool is_add, 126 void TouchBrowserFrameView::ViewHierarchyChanged(bool is_add,
123 View* parent, 127 View* parent,
124 View* child) { 128 View* child) {
125 OpaqueBrowserFrameView::ViewHierarchyChanged(is_add, parent, child); 129 OpaqueBrowserFrameView::ViewHierarchyChanged(is_add, parent, child);
126 if (!GetFocusManager()) 130 if (!GetFocusManager())
127 return; 131 return;
128 132
129 if (is_add && !focus_listener_added_) { 133 if (is_add && !focus_listener_added_) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 animation_->Show(); 171 animation_->Show();
168 172
169 // We don't re-layout the client view until the animation ends (see 173 // We don't re-layout the client view until the animation ends (see
170 // AnimationEnded below) because we want the client view to occupy the 174 // AnimationEnded below) because we want the client view to occupy the
171 // entire height during the animation. 175 // entire height during the animation.
172 Layout(); 176 Layout();
173 } else { 177 } else {
174 animation_->Hide(); 178 animation_->Hide();
175 179
176 browser_view()->set_clip_y(ui::Tween::ValueBetween( 180 browser_view()->set_clip_y(ui::Tween::ValueBetween(
177 animation_->GetCurrentValue(), 0, kKeyboardHeight)); 181 animation_->GetCurrentValue(), 0, keyboard_height_));
178 parent()->Layout(); 182 parent()->Layout();
179 } 183 }
180 } 184 }
181 185
182 TouchBrowserFrameView::VirtualKeyboardType 186 TouchBrowserFrameView::VirtualKeyboardType
183 TouchBrowserFrameView::DecideKeyboardStateForView(views::View* view) { 187 TouchBrowserFrameView::DecideKeyboardStateForView(views::View* view) {
184 if (!view) 188 if (!view)
185 return NONE; 189 return NONE;
186 190
187 std::string cname = view->GetClassName(); 191 std::string cname = view->GetClassName();
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 } else if (type == NotificationType::PREF_CHANGED) { 283 } else if (type == NotificationType::PREF_CHANGED) {
280 OpaqueBrowserFrameView::Observe(type, source, details); 284 OpaqueBrowserFrameView::Observe(type, source, details);
281 } else if (type == NotificationType::HIDE_KEYBOARD_INVOKED) { 285 } else if (type == NotificationType::HIDE_KEYBOARD_INVOKED) {
282 TabContents* tab_contents = 286 TabContents* tab_contents =
283 browser_view()->browser()->GetSelectedTabContents(); 287 browser_view()->browser()->GetSelectedTabContents();
284 if (tab_contents) { 288 if (tab_contents) {
285 GetFocusedStateAccessor()->SetProperty(tab_contents->property_bag(), 289 GetFocusedStateAccessor()->SetProperty(tab_contents->property_bag(),
286 false); 290 false);
287 } 291 }
288 UpdateKeyboardAndLayout(false); 292 UpdateKeyboardAndLayout(false);
293 } else if (type == NotificationType::SET_KEYBOARD_HEIGHT_INVOKED) {
294 int height = *reinterpret_cast<int*>(details.map_key());
295 if (height != keyboard_height_) {
bryeung 2011/06/03 19:14:52 we need to do more error checking here, e.g.: - d
Peng 2011/06/03 22:22:10 Done.
296 keyboard_height_ = height;
297 parent()->Layout();
298 }
289 } 299 }
290 } 300 }
291 301
292 /////////////////////////////////////////////////////////////////////////////// 302 ///////////////////////////////////////////////////////////////////////////////
293 // ui::AnimationDelegate implementation 303 // ui::AnimationDelegate implementation
294 void TouchBrowserFrameView::AnimationProgressed(const ui::Animation* anim) { 304 void TouchBrowserFrameView::AnimationProgressed(const ui::Animation* anim) {
295 ui::Transform transform; 305 ui::Transform transform;
296 transform.SetTranslateY( 306 transform.SetTranslateY(
297 ui::Tween::ValueBetween(anim->GetCurrentValue(), kKeyboardHeight, 0)); 307 ui::Tween::ValueBetween(anim->GetCurrentValue(), keyboard_height_, 0));
298 keyboard_->SetTransform(transform); 308 keyboard_->SetTransform(transform);
299 browser_view()->set_clip_y( 309 browser_view()->set_clip_y(
300 ui::Tween::ValueBetween(anim->GetCurrentValue(), 0, kKeyboardHeight)); 310 ui::Tween::ValueBetween(anim->GetCurrentValue(), 0, keyboard_height_));
301 SchedulePaint(); 311 SchedulePaint();
302 } 312 }
303 313
304 void TouchBrowserFrameView::AnimationEnded(const ui::Animation* animation) { 314 void TouchBrowserFrameView::AnimationEnded(const ui::Animation* animation) {
305 browser_view()->set_clip_y(0); 315 browser_view()->set_clip_y(0);
306 if (keyboard_showing_) { 316 if (keyboard_showing_) {
307 // Because the NonClientFrameView is a sibling of the ClientView, we rely on 317 // Because the NonClientFrameView is a sibling of the ClientView, we rely on
308 // the parent to resize the ClientView instead of resizing it directly. 318 // the parent to resize the ClientView instead of resizing it directly.
309 parent()->Layout(); 319 parent()->Layout();
310 320
311 // The keyboard that pops up may end up hiding the text entry. So make sure 321 // The keyboard that pops up may end up hiding the text entry. So make sure
312 // the renderer scrolls when necessary to keep the textfield visible. 322 // the renderer scrolls when necessary to keep the textfield visible.
313 RenderViewHost* host = 323 RenderViewHost* host =
314 browser_view()->browser()->GetSelectedTabContents()->render_view_host(); 324 browser_view()->browser()->GetSelectedTabContents()->render_view_host();
315 host->Send(new ViewMsg_ScrollFocusedEditableNodeIntoView( 325 host->Send(new ViewMsg_ScrollFocusedEditableNodeIntoView(
316 host->routing_id())); 326 host->routing_id()));
317 } 327 }
318 SchedulePaint(); 328 SchedulePaint();
319 } 329 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698