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

Unified Diff: chrome/browser/ui/touch/frame/touch_browser_frame_view.cc

Issue 7217008: Use input method to control visibility of virtual keyboard (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Update Created 9 years, 6 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/frame/touch_browser_frame_view.cc
diff --git a/chrome/browser/ui/touch/frame/touch_browser_frame_view.cc b/chrome/browser/ui/touch/frame/touch_browser_frame_view.cc
index 50d3367b86c81b92a3b2adb923c7ccce7ead3b33..eb109e7e5dcbe15e0ec79c0a2cc3f69ce28ed3a8 100644
--- a/chrome/browser/ui/touch/frame/touch_browser_frame_view.cc
+++ b/chrome/browser/ui/touch/frame/touch_browser_frame_view.cc
@@ -6,16 +6,11 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/renderer_host/render_widget_host_view_views.h"
-#include "chrome/browser/tabs/tab_strip_model.h"
#include "chrome/browser/ui/browser.h"
-#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
#include "chrome/browser/ui/touch/frame/keyboard_container_view.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
-#include "chrome/browser/ui/views/tab_contents/tab_contents_view_touch.h"
#include "content/browser/renderer_host/render_view_host.h"
-#include "content/browser/tab_contents/navigation_controller.h"
#include "content/browser/tab_contents/tab_contents.h"
-#include "content/browser/tab_contents/tab_contents_view.h"
#include "content/common/notification_service.h"
#include "content/common/notification_type.h"
#include "content/common/view_messages.h"
@@ -23,8 +18,6 @@
#include "ui/gfx/rect.h"
#include "ui/gfx/transform.h"
#include "views/controls/button/image_button.h"
-#include "views/controls/textfield/textfield.h"
-#include "views/focus/focus_manager.h"
#if defined(OS_CHROMEOS)
#include "chrome/browser/chromeos/cros/cros_library.h"
@@ -36,16 +29,6 @@ namespace {
const int kDefaultKeyboardHeight = 300;
const int kKeyboardSlideDuration = 300; // In milliseconds
-PropertyAccessor<bool>* GetFocusedStateAccessor() {
- static PropertyAccessor<bool> state;
- return &state;
-}
-
-bool TabContentsHasFocus(const TabContents* contents) {
- views::View* view = static_cast<TabContentsViewTouch*>(contents->view());
- return view->Contains(view->GetFocusManager()->GetFocusedView());
-}
-
} // namespace
// static
@@ -63,23 +46,12 @@ TouchBrowserFrameView::TouchBrowserFrameView(BrowserFrame* frame,
focus_listener_added_(false),
keyboard_(NULL) {
registrar_.Add(this,
- NotificationType::NAV_ENTRY_COMMITTED,
- NotificationService::AllSources());
- registrar_.Add(this,
- NotificationType::FOCUS_CHANGED_IN_PAGE,
- NotificationService::AllSources());
- registrar_.Add(this,
- NotificationType::TAB_CONTENTS_DESTROYED,
- NotificationService::AllSources());
- registrar_.Add(this,
NotificationType::HIDE_KEYBOARD_INVOKED,
NotificationService::AllSources());
registrar_.Add(this,
NotificationType::SET_KEYBOARD_HEIGHT_INVOKED,
NotificationService::AllSources());
- browser_view->browser()->tabstrip_model()->AddObserver(this);
-
animation_.reset(new ui::SlideAnimation(this));
animation_->SetTweenType(ui::Tween::LINEAR);
animation_->SetSlideDuration(kKeyboardSlideDuration);
@@ -92,7 +64,6 @@ TouchBrowserFrameView::TouchBrowserFrameView(BrowserFrame* frame,
}
TouchBrowserFrameView::~TouchBrowserFrameView() {
- browser_view()->browser()->tabstrip_model()->RemoveObserver(this);
}
std::string TouchBrowserFrameView::GetClassName() const {
@@ -118,16 +89,6 @@ void TouchBrowserFrameView::Layout() {
keyboard_->SetBoundsRect(bounds);
}
-void TouchBrowserFrameView::FocusWillChange(views::View* focused_before,
- views::View* focused_now) {
- VirtualKeyboardType before = DecideKeyboardStateForView(focused_before);
- VirtualKeyboardType now = DecideKeyboardStateForView(focused_now);
- if (before != now) {
- // TODO(varunjain): support other types of keyboard.
- UpdateKeyboardAndLayout(now == GENERIC);
- }
-}
-
///////////////////////////////////////////////////////////////////////////////
// TouchBrowserFrameView, protected:
@@ -139,17 +100,20 @@ void TouchBrowserFrameView::ViewHierarchyChanged(bool is_add,
View* parent,
View* child) {
OpaqueBrowserFrameView::ViewHierarchyChanged(is_add, parent, child);
- if (!GetFocusManager())
+ views::InputMethod* input_method = GetInputMethod();
+ if (!input_method)
return;
if (is_add && !focus_listener_added_) {
// Add focus listener when this view is added to the hierarchy.
- GetFocusManager()->AddFocusChangeListener(this);
+ input_method->AddTextInputTypeChangedListener(this);
focus_listener_added_ = true;
+ UpdateKeyboard(input_method->GetTextInputType());
} else if (!is_add && focus_listener_added_) {
// Remove focus listener when this view is removed from the hierarchy.
- GetFocusManager()->RemoveFocusChangeListener(this);
+ input_method->RemoveTextInputTypeChangedListener(this);
focus_listener_added_ = false;
+ UpdateKeyboardAndLayout(false);
}
}
@@ -169,6 +133,20 @@ void TouchBrowserFrameView::InitVirtualKeyboard() {
AddChildView(keyboard_);
}
+void TouchBrowserFrameView::UpdateKeyboard(ui::TextInputType type) {
+ switch (type) {
+ case ui::TEXT_INPUT_TYPE_NONE:
+ UpdateKeyboardAndLayout(false);
+ return;
+ case ui::TEXT_INPUT_TYPE_TEXT:
+ case ui::TEXT_INPUT_TYPE_PASSWORD:
+ default:
+ // TODO(penghuang): pass the input type to virtual keyboard.
+ UpdateKeyboardAndLayout(true);
+ return;
+ }
+}
+
void TouchBrowserFrameView::UpdateKeyboardAndLayout(bool should_show_keyboard) {
if (should_show_keyboard)
InitVirtualKeyboard();
@@ -199,24 +177,6 @@ void TouchBrowserFrameView::UpdateKeyboardAndLayout(bool should_show_keyboard) {
}
}
-TouchBrowserFrameView::VirtualKeyboardType
- TouchBrowserFrameView::DecideKeyboardStateForView(views::View* view) {
- if (!view)
- return NONE;
-
- std::string cname = view->GetClassName();
- if (cname == views::Textfield::kViewClassName) {
- return GENERIC;
- } else if (cname == RenderWidgetHostViewViews::kViewClassName) {
- TabContents* contents = browser_view()->browser()->GetSelectedTabContents();
- bool* editable = contents ? GetFocusedStateAccessor()->GetProperty(
- contents->property_bag()) : NULL;
- if (editable && *editable)
- return GENERIC;
- }
- return NONE;
-}
-
bool TouchBrowserFrameView::HitTest(const gfx::Point& point) const {
if (OpaqueBrowserFrameView::HitTest(point))
return true;
@@ -237,93 +197,29 @@ bool TouchBrowserFrameView::HitTest(const gfx::Point& point) const {
return false;
}
-void TouchBrowserFrameView::ActiveTabChanged(TabContentsWrapper* old_contents,
- TabContentsWrapper* new_contents,
- int index,
- bool user_gesture) {
- if (new_contents == old_contents)
- return;
-
- TabContents* contents = new_contents->tab_contents();
- if (!TabContentsHasFocus(contents))
- return;
-
- bool* editable = GetFocusedStateAccessor()->GetProperty(
- contents->property_bag());
- UpdateKeyboardAndLayout(editable ? *editable : false);
-}
-
-void TouchBrowserFrameView::TabStripEmpty() {
- if (animation_->is_animating()) {
- // Reset the delegate so the AnimationEnded callback doesn't trigger.
- animation_->set_delegate(NULL);
- animation_->Stop();
- }
-}
-
void TouchBrowserFrameView::Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details) {
- Browser* browser = browser_view()->browser();
- if (type == NotificationType::FOCUS_CHANGED_IN_PAGE) {
- // Only modify the keyboard state if the currently active tab sent the
- // notification.
- const TabContents* current_tab = browser->GetSelectedTabContents();
- TabContents* source_tab = Source<TabContents>(source).ptr();
- const bool editable = *Details<const bool>(details).ptr();
-
- if (current_tab == source_tab && TabContentsHasFocus(source_tab))
- UpdateKeyboardAndLayout(editable);
-
- // Save the state of the focused field so that the keyboard visibility
bryeung 2011/06/22 01:56:02 Is the IME TextInputTypeChanged notification someh
Peng 2011/06/22 04:17:39 Yes. But currently it only supports three types (N
- // can be determined after tab switching.
- GetFocusedStateAccessor()->SetProperty(
- source_tab->property_bag(), editable);
- } else if (type == NotificationType::NAV_ENTRY_COMMITTED) {
- NavigationController* controller =
- Source<NavigationController>(source).ptr();
- Browser* source_browser = Browser::GetBrowserForController(
- controller, NULL);
-
- // If the Browser for the keyboard has navigated, re-evaluate the visibility
- // of the keyboard.
- TouchBrowserFrameView::VirtualKeyboardType keyboard_type = NONE;
- views::View* view = GetFocusManager()->GetFocusedView();
- if (view) {
- if (view->GetClassName() == views::Textfield::kViewClassName)
- keyboard_type = GENERIC;
- if (view->GetClassName() == RenderWidgetHostViewViews::kViewClassName) {
- // Reset the state of the focused field in the current tab.
- GetFocusedStateAccessor()->SetProperty(
- controller->tab_contents()->property_bag(), false);
+ switch (type.value) {
+ case NotificationType::HIDE_KEYBOARD_INVOKED:
+ UpdateKeyboardAndLayout(false);
+ return;
+ case NotificationType::SET_KEYBOARD_HEIGHT_INVOKED: {
+ // TODO(penghuang) Allow extension conrtol the virtual keyboard directly
+ // instead of using Notification.
+ int height = *reinterpret_cast<int*>(details.map_key());
+ if (height != keyboard_height_) {
+ DCHECK_GE(height, 0) << "Height of the keyboard is less than 0.";
+ DCHECK_LE(height, View::height()) << "Height of the keyboard is greater"
+ " than the height of frame view.";
+ keyboard_height_ = height;
+ parent()->Layout();
}
+ return;
}
- if (source_browser == browser)
- UpdateKeyboardAndLayout(keyboard_type == GENERIC);
- } else if (type == NotificationType::TAB_CONTENTS_DESTROYED) {
- GetFocusedStateAccessor()->DeleteProperty(
- Source<TabContents>(source).ptr()->property_bag());
- } else if (type == NotificationType::PREF_CHANGED) {
- OpaqueBrowserFrameView::Observe(type, source, details);
- } else if (type == NotificationType::HIDE_KEYBOARD_INVOKED) {
- TabContents* tab_contents =
- browser_view()->browser()->GetSelectedTabContents();
- if (tab_contents) {
- GetFocusedStateAccessor()->SetProperty(tab_contents->property_bag(),
- false);
- }
- UpdateKeyboardAndLayout(false);
- } else if (type == NotificationType::SET_KEYBOARD_HEIGHT_INVOKED) {
- // TODO(penghuang) Allow extension conrtol the virtual keyboard directly
- // instead of using Notification.
- int height = *reinterpret_cast<int*>(details.map_key());
- if (height != keyboard_height_) {
- DCHECK_GE(height, 0) << "Height of the keyboard is less than 0.";
- DCHECK_LE(height, View::height()) << "Height of the keyboard is greater "
- "than the height of frame view.";
- keyboard_height_ = height;
- parent()->Layout();
- }
+ default:
+ OpaqueBrowserFrameView::Observe(type, source, details);
+ return;
}
}
@@ -372,3 +268,10 @@ void TouchBrowserFrameView::VirtualKeyboardChanged(
VLOG(1) << "VirtualKeyboardChanged: Switched to " << url.spec();
}
#endif
+
+///////////////////////////////////////////////////////////////////////////////
+// views::TextInputTypeChangedListener implementation
+void TouchBrowserFrameView::TextInputTypeChanged(
+ views::View* view, ui::TextInputType type) {
+ UpdateKeyboard(type);
+}

Powered by Google App Engine
This is Rietveld 408576698