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

Unified Diff: chrome/browser/ui/touch/keyboard/keyboard_manager.cc

Issue 7553016: Use text input type to control visibility of virtual keyboard (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Created 9 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/touch/keyboard/keyboard_manager.cc
diff --git a/chrome/browser/ui/touch/keyboard/keyboard_manager.cc b/chrome/browser/ui/touch/keyboard/keyboard_manager.cc
index 974642c0adae7d6bbdb673424b0ab2ab612373f0..84e971ea03e8bf6c2b1043437321ad8fb814e672 100644
--- a/chrome/browser/ui/touch/keyboard/keyboard_manager.cc
+++ b/chrome/browser/ui/touch/keyboard/keyboard_manager.cc
@@ -32,22 +32,6 @@ namespace {
const int kDefaultKeyboardHeight = 300;
const int kKeyboardSlideDuration = 300; // In milliseconds
-PropertyAccessor<bool>* GetFocusedStateAccessor() {
- static PropertyAccessor<bool> state;
- return &state;
-}
-
-// Returns whether the keyboard visibility should be affected by this tab.
-bool TabContentsCanAffectKeyboard(const TabContents* tab_contents) {
- // There may not be a browser, e.g. for the login window. But if there is
- // a browser, then |tab_contents| should be the active tab.
- Browser* browser = Browser::GetBrowserForController(
- &tab_contents->controller(), NULL);
- return browser == NULL ||
- (browser == BrowserList::GetLastActive() &&
- browser->GetSelectedTabContents() == tab_contents);
-}
-
} // namespace
// TODO(sad): Is the default profile always going to be the one we want?
@@ -82,17 +66,7 @@ KeyboardManager::KeyboardManager()
animation_->SetTweenType(ui::Tween::LINEAR);
animation_->SetSlideDuration(kKeyboardSlideDuration);
- // Start listening to notifications to maintain the keyboard visibility, size
- // etc.
- registrar_.Add(this,
- content::NOTIFICATION_NAV_ENTRY_COMMITTED,
- NotificationService::AllSources());
- registrar_.Add(this,
- content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE,
- NotificationService::AllSources());
- registrar_.Add(this,
- content::NOTIFICATION_TAB_CONTENTS_DESTROYED,
- NotificationService::AllSources());
+ views::TextInputTypeTracker::GetInstance()->AddTextInputTypeObserver(this);
registrar_.Add(this,
chrome::NOTIFICATION_HIDE_KEYBOARD_INVOKED,
NotificationService::AllSources());
@@ -114,6 +88,7 @@ KeyboardManager::KeyboardManager()
}
KeyboardManager::~KeyboardManager() {
+ views::TextInputTypeTracker::GetInstance()->RemoveTextInputTypeObserver(this);
#if defined(OS_CHROMEOS)
chromeos::input_method::InputMethodManager* manager =
chromeos::input_method::InputMethodManager::GetInstance();
@@ -162,14 +137,6 @@ void KeyboardManager::AnimationEnded(const ui::Animation* animation) {
Widget::Hide();
}
-void KeyboardManager::OnBrowserAdded(const Browser* browser) {
- browser->tabstrip_model()->AddObserver(this);
-}
-
-void KeyboardManager::OnBrowserRemoved(const Browser* browser) {
- browser->tabstrip_model()->RemoveObserver(this);
-}
-
bool KeyboardManager::OnMessageReceived(const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(KeyboardManager, message)
@@ -185,27 +152,13 @@ void KeyboardManager::OnRequest(
dom_view_->tab_contents()->render_view_host());
}
-void KeyboardManager::ActiveTabChanged(TabContentsWrapper* old_contents,
- TabContentsWrapper* new_contents,
- int index,
- bool user_gesture) {
- TabContents* contents = new_contents->tab_contents();
- if (!TabContentsCanAffectKeyboard(contents))
- return;
-
- // If the tab contents does not have the focus, then it should not affect the
- // keyboard visibility.
- views::View* view = static_cast<TabContentsViewTouch*>(contents->view());
- views::FocusManager* fmanager = view ? view->GetFocusManager() : NULL;
- if (!fmanager || !view->Contains(fmanager->GetFocusedView()))
- return;
-
- bool* editable = GetFocusedStateAccessor()->GetProperty(
- contents->property_bag());
- if (editable && *editable)
- ShowKeyboardForWidget(view->GetWidget());
- else
+void KeyboardManager::TextInputTypeChanged(ui::TextInputType type,
+ views::Widget *widget)
+{
+ if (type == ui::TEXT_INPUT_TYPE_NONE)
Hide();
+ else
+ ShowKeyboardForWidget(widget);
sadrul 2011/08/02 16:15:14 Please add a TODO for using 'type'
Peng 2011/08/03 16:30:55 Done.
}
Browser* KeyboardManager::GetBrowser() {
@@ -238,69 +191,7 @@ void KeyboardManager::Observe(int type,
const NotificationSource& source,
const NotificationDetails& details) {
switch (type) {
- case content::NOTIFICATION_NAV_ENTRY_COMMITTED: {
- // When a navigation happens, we want to hide the keyboard if the focus is
- // in the web-page. Otherwise, the keyboard visibility should not change.
- NavigationController* controller =
- Source<NavigationController>(source).ptr();
- TabContents* tab_contents = controller->tab_contents();
- GetFocusedStateAccessor()->SetProperty(tab_contents->property_bag(),
- false);
- if (!TabContentsCanAffectKeyboard(tab_contents))
- break;
-
- TabContentsViewTouch* view =
- static_cast<TabContentsViewTouch*>(tab_contents->view());
- views::View* focused = view->GetFocusManager()->GetFocusedView();
- views::TextInputClient* input =
- focused ? focused->GetTextInputClient() : NULL;
- // Show the keyboard if the focused view supports text-input.
- if (input && input->GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE)
- ShowKeyboardForWidget(focused->GetWidget());
- else
- Hide();
- break;
- }
-
- case content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE: {
- // If the focus in the page moved to an editable field, then the keyboard
- // should be visible, otherwise not.
- TabContents* tab_contents = Source<TabContents>(source).ptr();
- const bool editable = *Details<const bool>(details).ptr();
- GetFocusedStateAccessor()->SetProperty(tab_contents->property_bag(),
- editable);
- if (!TabContentsCanAffectKeyboard(tab_contents))
- break;
-
- if (editable) {
- TabContentsViewTouch* view =
- static_cast<TabContentsViewTouch*>(tab_contents->view());
- ShowKeyboardForWidget(view->GetWidget());
- } else {
- Hide();
- }
-
- break;
- }
-
- case content::NOTIFICATION_TAB_CONTENTS_DESTROYED: {
- // Tab content was destroyed. Forget everything about it.
- GetFocusedStateAccessor()->DeleteProperty(
- Source<TabContents>(source).ptr()->property_bag());
- break;
- }
-
case chrome::NOTIFICATION_HIDE_KEYBOARD_INVOKED: {
- // The keyboard is hiding itself.
- Browser* browser = BrowserList::GetLastActive();
- if (browser) {
- TabContents* tab_contents = browser->GetSelectedTabContents();
- if (tab_contents) {
- GetFocusedStateAccessor()->SetProperty(tab_contents->property_bag(),
- false);
- }
- }
-
Hide();
break;
}

Powered by Google App Engine
This is Rietveld 408576698