| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_view_host.h" | 8 #include "chrome/browser/renderer_host/render_view_host.h" |
| 9 #include "chrome/browser/tab_contents/navigation_controller.h" | 9 #include "chrome/browser/tab_contents/navigation_controller.h" |
| 10 #include "chrome/browser/tab_contents/tab_contents.h" | 10 #include "chrome/browser/tab_contents/tab_contents.h" |
| 11 #include "chrome/browser/tabs/tab_strip_model.h" | 11 #include "chrome/browser/tabs/tab_strip_model.h" |
| 12 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
| 13 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 13 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 14 #include "chrome/browser/ui/touch/frame/keyboard_container_view.h" | 14 #include "chrome/browser/ui/touch/frame/keyboard_container_view.h" |
| 15 #include "chrome/browser/ui/views/frame/browser_view.h" | 15 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 16 #include "chrome/common/notification_service.h" | 16 #include "chrome/common/notification_service.h" |
| 17 #include "chrome/common/notification_type.h" | 17 #include "chrome/common/notification_type.h" |
| 18 #include "ui/gfx/rect.h" | 18 #include "ui/gfx/rect.h" |
| 19 #include "views/controls/textfield/textfield.h" |
| 19 | 20 |
| 20 namespace { | 21 namespace { |
| 21 | 22 |
| 22 const int kKeyboardHeight = 300; | 23 const int kKeyboardHeight = 300; |
| 23 | 24 |
| 25 TouchBrowserFrameView::VirtualKeyboardType GetKeyboardType(views::View* view) { |
| 26 if (view->GetClassName().compare(views::Textfield::kViewClassName) == 0) |
| 27 return TouchBrowserFrameView::GENERIC; |
| 28 return TouchBrowserFrameView::NONE; |
| 29 } |
| 30 |
| 24 PropertyAccessor<bool>* GetFocusedStateAccessor() { | 31 PropertyAccessor<bool>* GetFocusedStateAccessor() { |
| 25 static PropertyAccessor<bool> state; | 32 static PropertyAccessor<bool> state; |
| 26 return &state; | 33 return &state; |
| 27 } | 34 } |
| 28 | 35 |
| 29 } // namespace | 36 } // namespace |
| 30 | 37 |
| 31 /////////////////////////////////////////////////////////////////////////////// | 38 /////////////////////////////////////////////////////////////////////////////// |
| 32 // TouchBrowserFrameView, public: | 39 // TouchBrowserFrameView, public: |
| 33 | 40 |
| 34 TouchBrowserFrameView::TouchBrowserFrameView(BrowserFrame* frame, | 41 TouchBrowserFrameView::TouchBrowserFrameView(BrowserFrame* frame, |
| 35 BrowserView* browser_view) | 42 BrowserView* browser_view) |
| 36 : OpaqueBrowserFrameView(frame, browser_view), | 43 : OpaqueBrowserFrameView(frame, browser_view), |
| 37 keyboard_showing_(false), | 44 keyboard_showing_(false), |
| 45 focus_listener_added_(false), |
| 38 keyboard_(NULL) { | 46 keyboard_(NULL) { |
| 39 registrar_.Add(this, | 47 registrar_.Add(this, |
| 40 NotificationType::NAV_ENTRY_COMMITTED, | 48 NotificationType::NAV_ENTRY_COMMITTED, |
| 41 NotificationService::AllSources()); | 49 NotificationService::AllSources()); |
| 42 registrar_.Add(this, | 50 registrar_.Add(this, |
| 43 NotificationType::FOCUS_CHANGED_IN_PAGE, | 51 NotificationType::FOCUS_CHANGED_IN_PAGE, |
| 44 NotificationService::AllSources()); | 52 NotificationService::AllSources()); |
| 45 registrar_.Add(this, | 53 registrar_.Add(this, |
| 46 NotificationType::TAB_CONTENTS_DESTROYED, | 54 NotificationType::TAB_CONTENTS_DESTROYED, |
| 47 NotificationService::AllSources()); | 55 NotificationService::AllSources()); |
| 48 | 56 |
| 49 browser_view->browser()->tabstrip_model()->AddObserver(this); | 57 browser_view->browser()->tabstrip_model()->AddObserver(this); |
| 50 } | 58 } |
| 51 | 59 |
| 52 TouchBrowserFrameView::~TouchBrowserFrameView() { | 60 TouchBrowserFrameView::~TouchBrowserFrameView() { |
| 53 browser_view()->browser()->tabstrip_model()->RemoveObserver(this); | 61 browser_view()->browser()->tabstrip_model()->RemoveObserver(this); |
| 54 } | 62 } |
| 55 | 63 |
| 56 void TouchBrowserFrameView::Layout() { | 64 void TouchBrowserFrameView::Layout() { |
| 57 OpaqueBrowserFrameView::Layout(); | 65 OpaqueBrowserFrameView::Layout(); |
| 58 | 66 |
| 59 if (!keyboard_) | 67 if (!keyboard_) |
| 60 return; | 68 return; |
| 61 | 69 |
| 62 keyboard_->SetVisible(keyboard_showing_); | 70 keyboard_->SetVisible(keyboard_showing_); |
| 63 keyboard_->SetBounds(GetBoundsForReservedArea()); | 71 keyboard_->SetBounds(GetBoundsForReservedArea()); |
| 64 } | 72 } |
| 65 | 73 |
| 74 void TouchBrowserFrameView::FocusWillChange(views::View* focused_before, |
| 75 views::View* focused_now) { |
| 76 if (!focused_before || |
| 77 (focused_now && GetKeyboardType(focused_now) |
| 78 != GetKeyboardType(focused_before))) { |
| 79 // TODO(varunjain): support other types of keyboard. |
| 80 UpdateKeyboardAndLayout(GetKeyboardType(focused_now) == GENERIC); |
| 81 } |
| 82 } |
| 83 |
| 66 /////////////////////////////////////////////////////////////////////////////// | 84 /////////////////////////////////////////////////////////////////////////////// |
| 67 // TouchBrowserFrameView, protected: | 85 // TouchBrowserFrameView, protected: |
| 68 int TouchBrowserFrameView::GetReservedHeight() const { | 86 int TouchBrowserFrameView::GetReservedHeight() const { |
| 69 if (keyboard_showing_) | 87 if (keyboard_showing_) |
| 70 return kKeyboardHeight; | 88 return kKeyboardHeight; |
| 71 | 89 |
| 72 return 0; | 90 return 0; |
| 73 } | 91 } |
| 74 | 92 |
| 93 void TouchBrowserFrameView::ViewHierarchyChanged(bool is_add, |
| 94 View* parent, |
| 95 View* child) { |
| 96 OpaqueBrowserFrameView::ViewHierarchyChanged(is_add, parent, child); |
| 97 if (!GetFocusManager()) |
| 98 return; |
| 99 |
| 100 if (is_add && !focus_listener_added_) { |
| 101 // Add focus listener when this view is added to the hierarchy. |
| 102 GetFocusManager()->AddFocusChangeListener(this); |
| 103 focus_listener_added_ = true; |
| 104 } else if (!is_add && focus_listener_added_) { |
| 105 // Remove focus listener when this view is removed from the hierarchy. |
| 106 GetFocusManager()->RemoveFocusChangeListener(this); |
| 107 focus_listener_added_ = false; |
| 108 } |
| 109 } |
| 110 |
| 75 /////////////////////////////////////////////////////////////////////////////// | 111 /////////////////////////////////////////////////////////////////////////////// |
| 76 // TouchBrowserFrameView, private: | 112 // TouchBrowserFrameView, private: |
| 77 | 113 |
| 78 void TouchBrowserFrameView::InitVirtualKeyboard() { | 114 void TouchBrowserFrameView::InitVirtualKeyboard() { |
| 79 if (keyboard_) | 115 if (keyboard_) |
| 80 return; | 116 return; |
| 81 | 117 |
| 82 Profile* keyboard_profile = browser_view()->browser()->profile(); | 118 Profile* keyboard_profile = browser_view()->browser()->profile(); |
| 83 DCHECK(keyboard_profile) << "Profile required for virtual keyboard."; | 119 DCHECK(keyboard_profile) << "Profile required for virtual keyboard."; |
| 84 | 120 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 Browser* source_browser = Browser::GetBrowserForController( | 181 Browser* source_browser = Browser::GetBrowserForController( |
| 146 Source<NavigationController>(source).ptr(), NULL); | 182 Source<NavigationController>(source).ptr(), NULL); |
| 147 // If the Browser for the keyboard has navigated, hide the keyboard. | 183 // If the Browser for the keyboard has navigated, hide the keyboard. |
| 148 if (source_browser == browser) | 184 if (source_browser == browser) |
| 149 UpdateKeyboardAndLayout(false); | 185 UpdateKeyboardAndLayout(false); |
| 150 } else if (type == NotificationType::TAB_CONTENTS_DESTROYED) { | 186 } else if (type == NotificationType::TAB_CONTENTS_DESTROYED) { |
| 151 GetFocusedStateAccessor()->DeleteProperty( | 187 GetFocusedStateAccessor()->DeleteProperty( |
| 152 Source<TabContents>(source).ptr()->property_bag()); | 188 Source<TabContents>(source).ptr()->property_bag()); |
| 153 } | 189 } |
| 154 } | 190 } |
| OLD | NEW |