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

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

Issue 6384004: Browser should get notified if a views textfield changes focus. In addition, (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Modified according to comments Created 9 years, 10 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) 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 "gfx/rect.h" 18 #include "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
24 PropertyAccessor<bool>* GetFocusedStateAccessor() { 25 PropertyAccessor<bool>* GetFocusedStateAccessor() {
25 static PropertyAccessor<bool> state; 26 static PropertyAccessor<bool> state;
26 return &state; 27 return &state;
27 } 28 }
28 29
29 } // namespace 30 } // namespace
30 31
31 /////////////////////////////////////////////////////////////////////////////// 32 ///////////////////////////////////////////////////////////////////////////////
32 // TouchBrowserFrameView, public: 33 // TouchBrowserFrameView, public:
33 34
34 TouchBrowserFrameView::TouchBrowserFrameView(BrowserFrame* frame, 35 TouchBrowserFrameView::TouchBrowserFrameView(BrowserFrame* frame,
35 BrowserView* browser_view) 36 BrowserView* browser_view)
36 : OpaqueBrowserFrameView(frame, browser_view), 37 : OpaqueBrowserFrameView(frame, browser_view),
37 keyboard_showing_(false), 38 keyboard_showing_(false),
38 keyboard_(NULL) { 39 keyboard_(NULL),
40 focus_listener_added_(false) {
39 registrar_.Add(this, 41 registrar_.Add(this,
40 NotificationType::NAV_ENTRY_COMMITTED, 42 NotificationType::NAV_ENTRY_COMMITTED,
41 NotificationService::AllSources()); 43 NotificationService::AllSources());
42 registrar_.Add(this, 44 registrar_.Add(this,
43 NotificationType::FOCUS_CHANGED_IN_PAGE, 45 NotificationType::FOCUS_CHANGED_IN_PAGE,
44 NotificationService::AllSources()); 46 NotificationService::AllSources());
45 registrar_.Add(this, 47 registrar_.Add(this,
46 NotificationType::TAB_CONTENTS_DESTROYED, 48 NotificationType::TAB_CONTENTS_DESTROYED,
47 NotificationService::AllSources()); 49 NotificationService::AllSources());
48 50
49 browser_view->browser()->tabstrip_model()->AddObserver(this); 51 browser_view->browser()->tabstrip_model()->AddObserver(this);
50 } 52 }
51 53
52 TouchBrowserFrameView::~TouchBrowserFrameView() { 54 TouchBrowserFrameView::~TouchBrowserFrameView() {
53 browser_view()->browser()->tabstrip_model()->RemoveObserver(this); 55 browser_view()->browser()->tabstrip_model()->RemoveObserver(this);
54 } 56 }
55 57
56 void TouchBrowserFrameView::Layout() { 58 void TouchBrowserFrameView::Layout() {
57 OpaqueBrowserFrameView::Layout(); 59 OpaqueBrowserFrameView::Layout();
58 60
59 if (!keyboard_) 61 if (!keyboard_)
60 return; 62 return;
61 63
62 keyboard_->SetVisible(keyboard_showing_); 64 keyboard_->SetVisible(keyboard_showing_);
63 keyboard_->SetBounds(GetBoundsForReservedArea()); 65 keyboard_->SetBounds(GetBoundsForReservedArea());
64 } 66 }
65 67
68 void TouchBrowserFrameView::FocusWillChange(views::View* focused_before,
69 views::View* focused_now) {
70 if (!focused_before ||
71 (focused_now && GetKeyboardType(focused_now)
72 != GetKeyboardType(focused_before))) {
73 // TODO(varunjain): support other types of keyboard.
74 UpdateKeyboardAndLayout(GetKeyboardType(focused_now) == GENERIC);
75 }
76 }
77
66 /////////////////////////////////////////////////////////////////////////////// 78 ///////////////////////////////////////////////////////////////////////////////
67 // TouchBrowserFrameView, protected: 79 // TouchBrowserFrameView, protected:
68 int TouchBrowserFrameView::GetReservedHeight() const { 80 int TouchBrowserFrameView::GetReservedHeight() const {
69 if (keyboard_showing_) 81 if (keyboard_showing_)
70 return kKeyboardHeight; 82 return kKeyboardHeight;
71 83
72 return 0; 84 return 0;
73 } 85 }
74 86
87 void TouchBrowserFrameView::ViewHierarchyChanged(bool is_add,
88 View* parent,
89 View* child) {
90 OpaqueBrowserFrameView::ViewHierarchyChanged(is_add, parent, child);
91 if (!GetFocusManager() || child != this)
oshima 2011/02/04 10:15:27 child != this is not necessary. This does not work
varunjain 2011/02/04 16:38:46 Done.
92 return;
93
94 if (is_add && !focus_listener_added_) {
95 // Add focus listener when this view is added to the hierarchy.
96 GetFocusManager()->AddFocusChangeListener(this);
97 focus_listener_added_ = true;
98 } else if (!is_add && focus_listener_added_) {
99 // Remove focus listener when this view is removed from the hierarchy.
100 GetFocusManager()->RemoveFocusChangeListener(this);
101 focus_listener_added_ = false;
102 }
103 }
104
75 /////////////////////////////////////////////////////////////////////////////// 105 ///////////////////////////////////////////////////////////////////////////////
76 // TouchBrowserFrameView, private: 106 // TouchBrowserFrameView, private:
77 107
78 void TouchBrowserFrameView::InitVirtualKeyboard() { 108 void TouchBrowserFrameView::InitVirtualKeyboard() {
79 if (keyboard_) 109 if (keyboard_)
80 return; 110 return;
81 111
82 Profile* keyboard_profile = browser_view()->browser()->profile(); 112 Profile* keyboard_profile = browser_view()->browser()->profile();
83 DCHECK(keyboard_profile) << "Profile required for virtual keyboard."; 113 DCHECK(keyboard_profile) << "Profile required for virtual keyboard.";
84 114
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 Browser* source_browser = Browser::GetBrowserForController( 175 Browser* source_browser = Browser::GetBrowserForController(
146 Source<NavigationController>(source).ptr(), NULL); 176 Source<NavigationController>(source).ptr(), NULL);
147 // If the Browser for the keyboard has navigated, hide the keyboard. 177 // If the Browser for the keyboard has navigated, hide the keyboard.
148 if (source_browser == browser) 178 if (source_browser == browser)
149 UpdateKeyboardAndLayout(false); 179 UpdateKeyboardAndLayout(false);
150 } else if (type == NotificationType::TAB_CONTENTS_DESTROYED) { 180 } else if (type == NotificationType::TAB_CONTENTS_DESTROYED) {
151 GetFocusedStateAccessor()->DeleteProperty( 181 GetFocusedStateAccessor()->DeleteProperty(
152 Source<TabContents>(source).ptr()->property_bag()); 182 Source<TabContents>(source).ptr()->property_bag());
153 } 183 }
154 } 184 }
185
186 TouchBrowserFrameView::VirtualKeyboardType
187 TouchBrowserFrameView::GetKeyboardType(views::View* view) {
188 if (view->GetClassName().compare(views::Textfield::kViewClassName) == 0)
189 return GENERIC;
190 else
Ben Goodger (Google) 2011/02/04 15:57:22 nit: no else after return
varunjain 2011/02/04 16:38:46 Done.
191 return NONE;
192 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698