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

Unified Diff: examples/browser/browser.cc

Issue 840923002: Remove the keyboard from the browser demo. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « examples/BUILD.gn ('k') | examples/keyboard/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: examples/browser/browser.cc
diff --git a/examples/browser/browser.cc b/examples/browser/browser.cc
index bbe96adab5f11c751a54418af40ed26eac46f2ed..75502d30139f41036455fd590f9763a78a2a28e3 100644
--- a/examples/browser/browser.cc
+++ b/examples/browser/browser.cc
@@ -58,95 +58,6 @@ class BrowserLayoutManager : public views::LayoutManager {
DISALLOW_COPY_AND_ASSIGN(BrowserLayoutManager);
};
-// KeyboardManager handles notifying the windowmanager when views are focused.
-// To use create one and KeyboardManager will take care of all other details.
-//
-// TODO(sky): it would be nice if this were put in NativeWidgetViewManager, but
-// that requires NativeWidgetViewManager to take an IWindowManager. That may be
-// desirable anyway...
-class KeyboardManager
- : public views::FocusChangeListener,
- public ui::EventHandler,
- public views::WidgetObserver {
- public:
- KeyboardManager(views::Widget* widget,
- IWindowManager* window_manager,
- View* view)
- : widget_(widget),
- window_manager_(window_manager),
- view_(view),
- last_view_id_(0),
- focused_view_(NULL) {
- widget_->GetFocusManager()->AddFocusChangeListener(this);
- widget_->AddObserver(this);
- widget_->GetNativeView()->AddPostTargetHandler(this);
- }
-
- private:
- virtual ~KeyboardManager() {
- widget_->GetFocusManager()->RemoveFocusChangeListener(this);
- widget_->GetNativeView()->RemovePostTargetHandler(this);
- widget_->RemoveObserver(this);
-
- HideKeyboard();
- }
-
- void ShowKeyboard(views::View* view) {
- if (focused_view_ == view)
- return;
-
- const gfx::Rect bounds_in_widget =
- view->ConvertRectToWidget(gfx::Rect(view->bounds().size()));
- last_view_id_ = view_->id();
- window_manager_->ShowKeyboard(last_view_id_,
- Rect::From(bounds_in_widget));
- // TODO(sky): listen for view to be removed.
- focused_view_ = view;
- }
-
- void HideKeyboard() {
- if (!focused_view_)
- return;
-
- window_manager_->HideKeyboard(last_view_id_);
- last_view_id_ = 0;
- focused_view_ = NULL;
- }
-
- // views::FocusChangeListener:
- virtual void OnWillChangeFocus(views::View* focused_before,
- views::View* focused_now) override {
- }
- virtual void OnDidChangeFocus(views::View* focused_before,
- views::View* focused_now) override {
- if (focused_view_ && focused_now != focused_view_)
- HideKeyboard();
- }
-
- // ui::EventHandler:
- virtual void OnMouseEvent(ui::MouseEvent* event) override {
- views::View* focused_now = widget_->GetFocusManager()->GetFocusedView();
- if (focused_now &&
- focused_now->GetClassName() == views::Textfield::kViewClassName &&
- (event->flags() & ui::EF_FROM_TOUCH) != 0) {
- ShowKeyboard(focused_now);
- }
- }
-
- // views::WidgetObserver:
- virtual void OnWidgetDestroying(views::Widget* widget) override {
- delete this;
- }
-
- views::Widget* widget_;
- IWindowManager* window_manager_;
- View* view_;
- Id last_view_id_;
- views::View* focused_view_;
-
- DISALLOW_COPY_AND_ASSIGN(KeyboardManager);
-};
-
// This is the basics of creating a views widget with a textfield.
// TODO: cleanup!
class Browser : public ApplicationDelegate,
@@ -195,8 +106,6 @@ class Browser : public ApplicationDelegate,
params.delegate = widget_delegate;
params.bounds = gfx::Rect(view->bounds().width, view->bounds().height);
widget_->Init(params);
- // KeyboardManager handles deleting itself when the widget is destroyed.
- new KeyboardManager(widget_, window_manager_.get(), view);
widget_->Show();
textfield->RequestFocus();
}
« no previous file with comments | « examples/BUILD.gn ('k') | examples/keyboard/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698