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

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: Rebase on trunk 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 kDefaultKeyboardHeight = 300;
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_(kDefaultKeyboardHeight),
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 122
119 int TouchBrowserFrameView::GetReservedHeight() const { 123 int TouchBrowserFrameView::GetReservedHeight() const {
120 return keyboard_showing_ ? kKeyboardHeight : 0; 124 return keyboard_showing_ ? keyboard_height_ : 0;
121 } 125 }
122 126
123 void TouchBrowserFrameView::ViewHierarchyChanged(bool is_add, 127 void TouchBrowserFrameView::ViewHierarchyChanged(bool is_add,
124 View* parent, 128 View* parent,
125 View* child) { 129 View* child) {
126 OpaqueBrowserFrameView::ViewHierarchyChanged(is_add, parent, child); 130 OpaqueBrowserFrameView::ViewHierarchyChanged(is_add, parent, child);
127 if (!GetFocusManager()) 131 if (!GetFocusManager())
128 return; 132 return;
129 133
130 if (is_add && !focus_listener_added_) { 134 if (is_add && !focus_listener_added_) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 // when layout, and then start the animation. 176 // when layout, and then start the animation.
173 ui::Transform reset; 177 ui::Transform reset;
174 keyboard_->SetTransform(reset); 178 keyboard_->SetTransform(reset);
175 Layout(); 179 Layout();
176 180
177 animation_->Show(); 181 animation_->Show();
178 } else { 182 } else {
179 animation_->Hide(); 183 animation_->Hide();
180 184
181 browser_view()->set_clip_y(ui::Tween::ValueBetween( 185 browser_view()->set_clip_y(ui::Tween::ValueBetween(
182 animation_->GetCurrentValue(), 0, kKeyboardHeight)); 186 animation_->GetCurrentValue(), 0, keyboard_height_));
183 parent()->Layout(); 187 parent()->Layout();
184 } 188 }
185 } 189 }
186 190
187 TouchBrowserFrameView::VirtualKeyboardType 191 TouchBrowserFrameView::VirtualKeyboardType
188 TouchBrowserFrameView::DecideKeyboardStateForView(views::View* view) { 192 TouchBrowserFrameView::DecideKeyboardStateForView(views::View* view) {
189 if (!view) 193 if (!view)
190 return NONE; 194 return NONE;
191 195
192 std::string cname = view->GetClassName(); 196 std::string cname = view->GetClassName();
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 } else if (type == NotificationType::PREF_CHANGED) { 288 } else if (type == NotificationType::PREF_CHANGED) {
285 OpaqueBrowserFrameView::Observe(type, source, details); 289 OpaqueBrowserFrameView::Observe(type, source, details);
286 } else if (type == NotificationType::HIDE_KEYBOARD_INVOKED) { 290 } else if (type == NotificationType::HIDE_KEYBOARD_INVOKED) {
287 TabContents* tab_contents = 291 TabContents* tab_contents =
288 browser_view()->browser()->GetSelectedTabContents(); 292 browser_view()->browser()->GetSelectedTabContents();
289 if (tab_contents) { 293 if (tab_contents) {
290 GetFocusedStateAccessor()->SetProperty(tab_contents->property_bag(), 294 GetFocusedStateAccessor()->SetProperty(tab_contents->property_bag(),
291 false); 295 false);
292 } 296 }
293 UpdateKeyboardAndLayout(false); 297 UpdateKeyboardAndLayout(false);
298 } else if (type == NotificationType::SET_KEYBOARD_HEIGHT_INVOKED) {
299 // TODO(penghuang) Allow extension conrtol the virtual keyboard directly
300 // instead of using Notification.
301 int height = *reinterpret_cast<int*>(details.map_key());
302 if (height != keyboard_height_) {
303 DCHECK_GE(height, 0) << "Height of the keyboard is less than 0.";
304 DCHECK_LE(height, View::height()) << "Height of the keyboard is greater "
305 "than the height of frame view.";
306 keyboard_height_ = height;
307 parent()->Layout();
308 }
294 } 309 }
295 } 310 }
296 311
297 /////////////////////////////////////////////////////////////////////////////// 312 ///////////////////////////////////////////////////////////////////////////////
298 // ui::AnimationDelegate implementation 313 // ui::AnimationDelegate implementation
299 void TouchBrowserFrameView::AnimationProgressed(const ui::Animation* anim) { 314 void TouchBrowserFrameView::AnimationProgressed(const ui::Animation* anim) {
300 ui::Transform transform; 315 ui::Transform transform;
301 transform.SetTranslateY( 316 transform.SetTranslateY(
302 ui::Tween::ValueBetween(anim->GetCurrentValue(), kKeyboardHeight, 0)); 317 ui::Tween::ValueBetween(anim->GetCurrentValue(), keyboard_height_, 0));
303 keyboard_->SetTransform(transform); 318 keyboard_->SetTransform(transform);
304 browser_view()->set_clip_y( 319 browser_view()->set_clip_y(
305 ui::Tween::ValueBetween(anim->GetCurrentValue(), 0, kKeyboardHeight)); 320 ui::Tween::ValueBetween(anim->GetCurrentValue(), 0, keyboard_height_));
306 SchedulePaint(); 321 SchedulePaint();
307 } 322 }
308 323
309 void TouchBrowserFrameView::AnimationEnded(const ui::Animation* animation) { 324 void TouchBrowserFrameView::AnimationEnded(const ui::Animation* animation) {
310 browser_view()->set_clip_y(0); 325 browser_view()->set_clip_y(0);
311 if (keyboard_showing_) { 326 if (keyboard_showing_) {
312 // Because the NonClientFrameView is a sibling of the ClientView, we rely on 327 // Because the NonClientFrameView is a sibling of the ClientView, we rely on
313 // the parent to resize the ClientView instead of resizing it directly. 328 // the parent to resize the ClientView instead of resizing it directly.
314 parent()->Layout(); 329 parent()->Layout();
315 330
316 // The keyboard that pops up may end up hiding the text entry. So make sure 331 // The keyboard that pops up may end up hiding the text entry. So make sure
317 // the renderer scrolls when necessary to keep the textfield visible. 332 // the renderer scrolls when necessary to keep the textfield visible.
318 RenderViewHost* host = 333 RenderViewHost* host =
319 browser_view()->browser()->GetSelectedTabContents()->render_view_host(); 334 browser_view()->browser()->GetSelectedTabContents()->render_view_host();
320 host->Send(new ViewMsg_ScrollFocusedEditableNodeIntoView( 335 host->Send(new ViewMsg_ScrollFocusedEditableNodeIntoView(
321 host->routing_id())); 336 host->routing_id()));
322 } else { 337 } else {
323 // Notify the keyboard that it is hidden now. 338 // Notify the keyboard that it is hidden now.
324 keyboard_->SetVisible(false); 339 keyboard_->SetVisible(false);
325 } 340 }
326 SchedulePaint(); 341 SchedulePaint();
327 } 342 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/touch/frame/touch_browser_frame_view.h ('k') | chrome/common/extensions/api/extension_api.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698