OLD | NEW |
---|---|
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 Loading... | |
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 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 Loading... | |
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 Loading... | |
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_) { | |
296 DCHECK_GE(height, 0) << "Height of the keyboar is less than 0."; | |
297 DCHECK_LE(height, View::height()) << "Height of the keyboard is great " | |
298 "than the height of frame view."; | |
299 keyboard_height_ = height; | |
bryeung
2011/06/07 22:45:03
Please do not set the height or call Layout if the
Peng
2011/06/08 14:59:57
I added code in extension_input_api.cc to check th
| |
300 parent()->Layout(); | |
301 } | |
289 } | 302 } |
290 } | 303 } |
291 | 304 |
292 /////////////////////////////////////////////////////////////////////////////// | 305 /////////////////////////////////////////////////////////////////////////////// |
293 // ui::AnimationDelegate implementation | 306 // ui::AnimationDelegate implementation |
294 void TouchBrowserFrameView::AnimationProgressed(const ui::Animation* anim) { | 307 void TouchBrowserFrameView::AnimationProgressed(const ui::Animation* anim) { |
295 ui::Transform transform; | 308 ui::Transform transform; |
296 transform.SetTranslateY( | 309 transform.SetTranslateY( |
297 ui::Tween::ValueBetween(anim->GetCurrentValue(), kKeyboardHeight, 0)); | 310 ui::Tween::ValueBetween(anim->GetCurrentValue(), keyboard_height_, 0)); |
298 keyboard_->SetTransform(transform); | 311 keyboard_->SetTransform(transform); |
299 browser_view()->set_clip_y( | 312 browser_view()->set_clip_y( |
300 ui::Tween::ValueBetween(anim->GetCurrentValue(), 0, kKeyboardHeight)); | 313 ui::Tween::ValueBetween(anim->GetCurrentValue(), 0, keyboard_height_)); |
301 SchedulePaint(); | 314 SchedulePaint(); |
302 } | 315 } |
303 | 316 |
304 void TouchBrowserFrameView::AnimationEnded(const ui::Animation* animation) { | 317 void TouchBrowserFrameView::AnimationEnded(const ui::Animation* animation) { |
305 browser_view()->set_clip_y(0); | 318 browser_view()->set_clip_y(0); |
306 if (keyboard_showing_) { | 319 if (keyboard_showing_) { |
307 // Because the NonClientFrameView is a sibling of the ClientView, we rely on | 320 // Because the NonClientFrameView is a sibling of the ClientView, we rely on |
308 // the parent to resize the ClientView instead of resizing it directly. | 321 // the parent to resize the ClientView instead of resizing it directly. |
309 parent()->Layout(); | 322 parent()->Layout(); |
310 | 323 |
311 // The keyboard that pops up may end up hiding the text entry. So make sure | 324 // 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. | 325 // the renderer scrolls when necessary to keep the textfield visible. |
313 RenderViewHost* host = | 326 RenderViewHost* host = |
314 browser_view()->browser()->GetSelectedTabContents()->render_view_host(); | 327 browser_view()->browser()->GetSelectedTabContents()->render_view_host(); |
315 host->Send(new ViewMsg_ScrollFocusedEditableNodeIntoView( | 328 host->Send(new ViewMsg_ScrollFocusedEditableNodeIntoView( |
316 host->routing_id())); | 329 host->routing_id())); |
317 } | 330 } |
318 SchedulePaint(); | 331 SchedulePaint(); |
319 } | 332 } |
OLD | NEW |