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

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 reviewer comments Created 9 years, 11 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"
(...skipping 17 matching lines...) Expand all
28 28
29 } // namespace 29 } // namespace
30 30
31 /////////////////////////////////////////////////////////////////////////////// 31 ///////////////////////////////////////////////////////////////////////////////
32 // TouchBrowserFrameView, public: 32 // TouchBrowserFrameView, public:
33 33
34 TouchBrowserFrameView::TouchBrowserFrameView(BrowserFrame* frame, 34 TouchBrowserFrameView::TouchBrowserFrameView(BrowserFrame* frame,
35 BrowserView* browser_view) 35 BrowserView* browser_view)
36 : OpaqueBrowserFrameView(frame, browser_view), 36 : OpaqueBrowserFrameView(frame, browser_view),
37 keyboard_showing_(false), 37 keyboard_showing_(false),
38 keyboard_(NULL) { 38 keyboard_(NULL),
39 focus_listener_added_(false) {
39 registrar_.Add(this, 40 registrar_.Add(this,
40 NotificationType::NAV_ENTRY_COMMITTED, 41 NotificationType::NAV_ENTRY_COMMITTED,
41 NotificationService::AllSources()); 42 NotificationService::AllSources());
42 registrar_.Add(this, 43 registrar_.Add(this,
43 NotificationType::FOCUS_CHANGED_IN_PAGE, 44 NotificationType::FOCUS_CHANGED_IN_PAGE,
44 NotificationService::AllSources()); 45 NotificationService::AllSources());
45 registrar_.Add(this, 46 registrar_.Add(this,
46 NotificationType::TAB_CONTENTS_DESTROYED, 47 NotificationType::TAB_CONTENTS_DESTROYED,
47 NotificationService::AllSources()); 48 NotificationService::AllSources());
48 49
49 browser_view->browser()->tabstrip_model()->AddObserver(this); 50 browser_view->browser()->tabstrip_model()->AddObserver(this);
50 } 51 }
51 52
52 TouchBrowserFrameView::~TouchBrowserFrameView() { 53 TouchBrowserFrameView::~TouchBrowserFrameView() {
53 browser_view()->browser()->tabstrip_model()->RemoveObserver(this); 54 browser_view()->browser()->tabstrip_model()->RemoveObserver(this);
54 } 55 }
55 56
56 void TouchBrowserFrameView::Layout() { 57 void TouchBrowserFrameView::Layout() {
57 OpaqueBrowserFrameView::Layout(); 58 OpaqueBrowserFrameView::Layout();
58 59
59 if (!keyboard_) 60 if (!keyboard_)
60 return; 61 return;
61 62
62 keyboard_->SetVisible(keyboard_showing_); 63 keyboard_->SetVisible(keyboard_showing_);
63 keyboard_->SetBounds(GetBoundsForReservedArea()); 64 keyboard_->SetBounds(GetBoundsForReservedArea());
64 } 65 }
65 66
67 void TouchBrowserFrameView::FocusWillChange(views::View* focused_before,
68 views::View* focused_now) {
69 if (!focused_before ||
70 (focused_now && focused_now->GetContentType()
71 != focused_before->GetContentType())) {
72 // TODO: support other types of keyboard.
bryeung 2011/02/01 19:03:53 this should have a name attached to it
varunjain 2011/02/04 00:11:39 Done.
73 UpdateKeyboardAndLayout(
74 focused_now->GetContentType() == views::View::GENERIC_INPUT);
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 (is_add && child == this && !focus_listener_added_ && GetFocusManager()) {
bryeung 2011/02/01 19:03:53 Maybe this would be easier to understand if you pu
varunjain 2011/02/04 00:11:39 Done.
92 // Add focus listener when this view is added to the hierarchy.
93 GetFocusManager()->AddFocusChangeListener(this);
94 focus_listener_added_ = true;
95 } else if (!is_add && child == this
96 && focus_listener_added_ && GetFocusManager()) {
97 // Remove focus listener when this view is removed from the hierarchy.
98 GetFocusManager()->RemoveFocusChangeListener(this);
99 focus_listener_added_ = false;
100 }
101 }
102
75 /////////////////////////////////////////////////////////////////////////////// 103 ///////////////////////////////////////////////////////////////////////////////
76 // TouchBrowserFrameView, private: 104 // TouchBrowserFrameView, private:
77 105
78 void TouchBrowserFrameView::InitVirtualKeyboard() { 106 void TouchBrowserFrameView::InitVirtualKeyboard() {
79 if (keyboard_) 107 if (keyboard_)
80 return; 108 return;
81 109
82 Profile* keyboard_profile = browser_view()->browser()->profile(); 110 Profile* keyboard_profile = browser_view()->browser()->profile();
83 DCHECK(keyboard_profile) << "Profile required for virtual keyboard."; 111 DCHECK(keyboard_profile) << "Profile required for virtual keyboard.";
84 112
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 Browser* source_browser = Browser::GetBrowserForController( 173 Browser* source_browser = Browser::GetBrowserForController(
146 Source<NavigationController>(source).ptr(), NULL); 174 Source<NavigationController>(source).ptr(), NULL);
147 // If the Browser for the keyboard has navigated, hide the keyboard. 175 // If the Browser for the keyboard has navigated, hide the keyboard.
148 if (source_browser == browser) 176 if (source_browser == browser)
149 UpdateKeyboardAndLayout(false); 177 UpdateKeyboardAndLayout(false);
150 } else if (type == NotificationType::TAB_CONTENTS_DESTROYED) { 178 } else if (type == NotificationType::TAB_CONTENTS_DESTROYED) {
151 GetFocusedStateAccessor()->DeleteProperty( 179 GetFocusedStateAccessor()->DeleteProperty(
152 Source<TabContents>(source).ptr()->property_bag()); 180 Source<TabContents>(source).ptr()->property_bag());
153 } 181 }
154 } 182 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698