| 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" |
| 11 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 11 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 12 #include "chrome/browser/ui/touch/frame/keyboard_container_view.h" | 12 #include "chrome/browser/ui/touch/frame/keyboard_container_view.h" |
| 13 #include "chrome/browser/ui/views/frame/browser_view.h" | 13 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 14 #include "chrome/browser/ui/views/tab_contents/tab_contents_view_touch.h" | 14 #include "chrome/browser/ui/views/tab_contents/tab_contents_view_touch.h" |
| 15 #include "content/browser/renderer_host/render_view_host.h" | 15 #include "content/browser/renderer_host/render_view_host.h" |
| 16 #include "content/browser/tab_contents/navigation_controller.h" | 16 #include "content/browser/tab_contents/navigation_controller.h" |
| 17 #include "content/browser/tab_contents/tab_contents.h" | 17 #include "content/browser/tab_contents/tab_contents.h" |
| 18 #include "content/browser/tab_contents/tab_contents_view.h" | 18 #include "content/browser/tab_contents/tab_contents_view.h" |
| 19 #include "content/common/content_notification_types.h" |
| 19 #include "content/common/notification_service.h" | 20 #include "content/common/notification_service.h" |
| 20 #include "content/common/notification_type.h" | |
| 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 #if defined(OS_CHROMEOS) | 29 #if defined(OS_CHROMEOS) |
| 30 #include "chrome/browser/chromeos/input_method/virtual_keyboard_selector.h" | 30 #include "chrome/browser/chromeos/input_method/virtual_keyboard_selector.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 55 // TouchBrowserFrameView, public: | 55 // TouchBrowserFrameView, public: |
| 56 | 56 |
| 57 TouchBrowserFrameView::TouchBrowserFrameView(BrowserFrame* frame, | 57 TouchBrowserFrameView::TouchBrowserFrameView(BrowserFrame* frame, |
| 58 BrowserView* browser_view) | 58 BrowserView* browser_view) |
| 59 : OpaqueBrowserFrameView(frame, browser_view), | 59 : OpaqueBrowserFrameView(frame, browser_view), |
| 60 keyboard_showing_(false), | 60 keyboard_showing_(false), |
| 61 keyboard_height_(kDefaultKeyboardHeight), | 61 keyboard_height_(kDefaultKeyboardHeight), |
| 62 focus_listener_added_(false), | 62 focus_listener_added_(false), |
| 63 keyboard_(NULL) { | 63 keyboard_(NULL) { |
| 64 registrar_.Add(this, | 64 registrar_.Add(this, |
| 65 NotificationType::NAV_ENTRY_COMMITTED, | 65 chrome::NAV_ENTRY_COMMITTED, |
| 66 NotificationService::AllSources()); | 66 NotificationService::AllSources()); |
| 67 registrar_.Add(this, | 67 registrar_.Add(this, |
| 68 NotificationType::FOCUS_CHANGED_IN_PAGE, | 68 chrome::FOCUS_CHANGED_IN_PAGE, |
| 69 NotificationService::AllSources()); | 69 NotificationService::AllSources()); |
| 70 registrar_.Add(this, | 70 registrar_.Add(this, |
| 71 NotificationType::TAB_CONTENTS_DESTROYED, | 71 chrome::TAB_CONTENTS_DESTROYED, |
| 72 NotificationService::AllSources()); | 72 NotificationService::AllSources()); |
| 73 registrar_.Add(this, | 73 registrar_.Add(this, |
| 74 NotificationType::HIDE_KEYBOARD_INVOKED, | 74 chrome::HIDE_KEYBOARD_INVOKED, |
| 75 NotificationService::AllSources()); | 75 NotificationService::AllSources()); |
| 76 registrar_.Add(this, | 76 registrar_.Add(this, |
| 77 NotificationType::SET_KEYBOARD_HEIGHT_INVOKED, | 77 chrome::SET_KEYBOARD_HEIGHT_INVOKED, |
| 78 NotificationService::AllSources()); | 78 NotificationService::AllSources()); |
| 79 registrar_.Add(this, | 79 registrar_.Add(this, |
| 80 NotificationType::EDITABLE_ELEMENT_TOUCHED, | 80 chrome::EDITABLE_ELEMENT_TOUCHED, |
| 81 NotificationService::AllSources()); | 81 NotificationService::AllSources()); |
| 82 | 82 |
| 83 browser_view->browser()->tabstrip_model()->AddObserver(this); | 83 browser_view->browser()->tabstrip_model()->AddObserver(this); |
| 84 | 84 |
| 85 animation_.reset(new ui::SlideAnimation(this)); | 85 animation_.reset(new ui::SlideAnimation(this)); |
| 86 animation_->SetTweenType(ui::Tween::LINEAR); | 86 animation_->SetTweenType(ui::Tween::LINEAR); |
| 87 animation_->SetSlideDuration(kKeyboardSlideDuration); | 87 animation_->SetSlideDuration(kKeyboardSlideDuration); |
| 88 | 88 |
| 89 #if defined(OS_CHROMEOS) | 89 #if defined(OS_CHROMEOS) |
| 90 chromeos::input_method::InputMethodManager* manager = | 90 chromeos::input_method::InputMethodManager* manager = |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 } | 253 } |
| 254 | 254 |
| 255 void TouchBrowserFrameView::TabStripEmpty() { | 255 void TouchBrowserFrameView::TabStripEmpty() { |
| 256 if (animation_->is_animating()) { | 256 if (animation_->is_animating()) { |
| 257 // Reset the delegate so the AnimationEnded callback doesn't trigger. | 257 // Reset the delegate so the AnimationEnded callback doesn't trigger. |
| 258 animation_->set_delegate(NULL); | 258 animation_->set_delegate(NULL); |
| 259 animation_->Stop(); | 259 animation_->Stop(); |
| 260 } | 260 } |
| 261 } | 261 } |
| 262 | 262 |
| 263 void TouchBrowserFrameView::Observe(NotificationType type, | 263 void TouchBrowserFrameView::Observe(int type, |
| 264 const NotificationSource& source, | 264 const NotificationSource& source, |
| 265 const NotificationDetails& details) { | 265 const NotificationDetails& details) { |
| 266 Browser* browser = browser_view()->browser(); | 266 Browser* browser = browser_view()->browser(); |
| 267 if (type == NotificationType::FOCUS_CHANGED_IN_PAGE) { | 267 if (type == chrome::FOCUS_CHANGED_IN_PAGE) { |
| 268 // Only modify the keyboard state if the currently active tab sent the | 268 // Only modify the keyboard state if the currently active tab sent the |
| 269 // notification. | 269 // notification. |
| 270 const TabContents* current_tab = browser->GetSelectedTabContents(); | 270 const TabContents* current_tab = browser->GetSelectedTabContents(); |
| 271 TabContents* source_tab = Source<TabContents>(source).ptr(); | 271 TabContents* source_tab = Source<TabContents>(source).ptr(); |
| 272 const bool editable = *Details<const bool>(details).ptr(); | 272 const bool editable = *Details<const bool>(details).ptr(); |
| 273 | 273 |
| 274 if (current_tab == source_tab && TabContentsHasFocus(source_tab)) | 274 if (current_tab == source_tab && TabContentsHasFocus(source_tab)) |
| 275 UpdateKeyboardAndLayout(editable); | 275 UpdateKeyboardAndLayout(editable); |
| 276 | 276 |
| 277 // Save the state of the focused field so that the keyboard visibility | 277 // Save the state of the focused field so that the keyboard visibility |
| 278 // can be determined after tab switching. | 278 // can be determined after tab switching. |
| 279 GetFocusedStateAccessor()->SetProperty( | 279 GetFocusedStateAccessor()->SetProperty( |
| 280 source_tab->property_bag(), editable); | 280 source_tab->property_bag(), editable); |
| 281 } else if (type == NotificationType::NAV_ENTRY_COMMITTED) { | 281 } else if (type == chrome::NAV_ENTRY_COMMITTED) { |
| 282 NavigationController* controller = | 282 NavigationController* controller = |
| 283 Source<NavigationController>(source).ptr(); | 283 Source<NavigationController>(source).ptr(); |
| 284 Browser* source_browser = Browser::GetBrowserForController( | 284 Browser* source_browser = Browser::GetBrowserForController( |
| 285 controller, NULL); | 285 controller, NULL); |
| 286 | 286 |
| 287 // If the Browser for the keyboard has navigated, re-evaluate the visibility | 287 // If the Browser for the keyboard has navigated, re-evaluate the visibility |
| 288 // of the keyboard. | 288 // of the keyboard. |
| 289 TouchBrowserFrameView::VirtualKeyboardType keyboard_type = NONE; | 289 TouchBrowserFrameView::VirtualKeyboardType keyboard_type = NONE; |
| 290 views::View* view = GetFocusManager()->GetFocusedView(); | 290 views::View* view = GetFocusManager()->GetFocusedView(); |
| 291 if (view) { | 291 if (view) { |
| 292 if (view->GetClassName() == views::Textfield::kViewClassName) | 292 if (view->GetClassName() == views::Textfield::kViewClassName) |
| 293 keyboard_type = GENERIC; | 293 keyboard_type = GENERIC; |
| 294 if (view->GetClassName() == RenderWidgetHostViewViews::kViewClassName) { | 294 if (view->GetClassName() == RenderWidgetHostViewViews::kViewClassName) { |
| 295 // Reset the state of the focused field in the current tab. | 295 // Reset the state of the focused field in the current tab. |
| 296 GetFocusedStateAccessor()->SetProperty( | 296 GetFocusedStateAccessor()->SetProperty( |
| 297 controller->tab_contents()->property_bag(), false); | 297 controller->tab_contents()->property_bag(), false); |
| 298 } | 298 } |
| 299 } | 299 } |
| 300 if (source_browser == browser) | 300 if (source_browser == browser) |
| 301 UpdateKeyboardAndLayout(keyboard_type == GENERIC); | 301 UpdateKeyboardAndLayout(keyboard_type == GENERIC); |
| 302 } else if (type == NotificationType::TAB_CONTENTS_DESTROYED) { | 302 } else if (type == chrome::TAB_CONTENTS_DESTROYED) { |
| 303 GetFocusedStateAccessor()->DeleteProperty( | 303 GetFocusedStateAccessor()->DeleteProperty( |
| 304 Source<TabContents>(source).ptr()->property_bag()); | 304 Source<TabContents>(source).ptr()->property_bag()); |
| 305 } else if (type == NotificationType::PREF_CHANGED) { | 305 } else if (type == chrome::PREF_CHANGED) { |
| 306 OpaqueBrowserFrameView::Observe(type, source, details); | 306 OpaqueBrowserFrameView::Observe(type, source, details); |
| 307 } else if (type == NotificationType::HIDE_KEYBOARD_INVOKED) { | 307 } else if (type == chrome::HIDE_KEYBOARD_INVOKED) { |
| 308 TabContents* tab_contents = | 308 TabContents* tab_contents = |
| 309 browser_view()->browser()->GetSelectedTabContents(); | 309 browser_view()->browser()->GetSelectedTabContents(); |
| 310 if (tab_contents) { | 310 if (tab_contents) { |
| 311 GetFocusedStateAccessor()->SetProperty(tab_contents->property_bag(), | 311 GetFocusedStateAccessor()->SetProperty(tab_contents->property_bag(), |
| 312 false); | 312 false); |
| 313 } | 313 } |
| 314 UpdateKeyboardAndLayout(false); | 314 UpdateKeyboardAndLayout(false); |
| 315 } else if (type == NotificationType::SET_KEYBOARD_HEIGHT_INVOKED) { | 315 } else if (type == chrome::SET_KEYBOARD_HEIGHT_INVOKED) { |
| 316 // TODO(penghuang) Allow extension conrtol the virtual keyboard directly | 316 // TODO(penghuang) Allow extension conrtol the virtual keyboard directly |
| 317 // instead of using Notification. | 317 // instead of using Notification. |
| 318 int height = *reinterpret_cast<int*>(details.map_key()); | 318 int height = *reinterpret_cast<int*>(details.map_key()); |
| 319 if (height != keyboard_height_) { | 319 if (height != keyboard_height_) { |
| 320 DCHECK_GE(height, 0) << "Height of the keyboard is less than 0."; | 320 DCHECK_GE(height, 0) << "Height of the keyboard is less than 0."; |
| 321 DCHECK_LE(height, View::height()) << "Height of the keyboard is greater " | 321 DCHECK_LE(height, View::height()) << "Height of the keyboard is greater " |
| 322 "than the height of frame view."; | 322 "than the height of frame view."; |
| 323 keyboard_height_ = height; | 323 keyboard_height_ = height; |
| 324 parent()->Layout(); | 324 parent()->Layout(); |
| 325 } | 325 } |
| 326 } else if (type == NotificationType::EDITABLE_ELEMENT_TOUCHED) { | 326 } else if (type == chrome::EDITABLE_ELEMENT_TOUCHED) { |
| 327 UpdateKeyboardAndLayout(true); | 327 UpdateKeyboardAndLayout(true); |
| 328 } | 328 } |
| 329 } | 329 } |
| 330 | 330 |
| 331 /////////////////////////////////////////////////////////////////////////////// | 331 /////////////////////////////////////////////////////////////////////////////// |
| 332 // ui::AnimationDelegate implementation | 332 // ui::AnimationDelegate implementation |
| 333 void TouchBrowserFrameView::AnimationProgressed(const ui::Animation* anim) { | 333 void TouchBrowserFrameView::AnimationProgressed(const ui::Animation* anim) { |
| 334 ui::Transform transform; | 334 ui::Transform transform; |
| 335 transform.SetTranslateY( | 335 transform.SetTranslateY( |
| 336 ui::Tween::ValueBetween(anim->GetCurrentValue(), keyboard_height_, 0)); | 336 ui::Tween::ValueBetween(anim->GetCurrentValue(), keyboard_height_, 0)); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 366 const chromeos::input_method::VirtualKeyboard& virtual_keyboard, | 366 const chromeos::input_method::VirtualKeyboard& virtual_keyboard, |
| 367 const std::string& virtual_keyboard_layout) { | 367 const std::string& virtual_keyboard_layout) { |
| 368 if (!keyboard_) | 368 if (!keyboard_) |
| 369 return; | 369 return; |
| 370 | 370 |
| 371 const GURL& url = virtual_keyboard.GetURLForLayout(virtual_keyboard_layout); | 371 const GURL& url = virtual_keyboard.GetURLForLayout(virtual_keyboard_layout); |
| 372 keyboard_->LoadURL(url); | 372 keyboard_->LoadURL(url); |
| 373 VLOG(1) << "VirtualKeyboardChanged: Switched to " << url.spec(); | 373 VLOG(1) << "VirtualKeyboardChanged: Switched to " << url.spec(); |
| 374 } | 374 } |
| 375 #endif | 375 #endif |
| OLD | NEW |