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

Side by Side Diff: ui/keyboard/keyboard_controller.cc

Issue 13726015: keyboard: Add a window delegate to the keyboard window container. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 8 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
« no previous file with comments | « no previous file | ui/keyboard/keyboard_controller_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "ui/keyboard/keyboard_controller.h" 5 #include "ui/keyboard/keyboard_controller.h"
6 6
7 #include "ui/aura/layout_manager.h" 7 #include "ui/aura/layout_manager.h"
8 #include "ui/aura/window.h" 8 #include "ui/aura/window.h"
9 #include "ui/aura/window_delegate.h"
10 #include "ui/base/hit_test.h"
11 #include "ui/gfx/path.h"
9 #include "ui/gfx/rect.h" 12 #include "ui/gfx/rect.h"
13 #include "ui/gfx/skia_util.h"
10 #include "ui/keyboard/keyboard_controller_proxy.h" 14 #include "ui/keyboard/keyboard_controller_proxy.h"
11 15
12 namespace { 16 namespace {
13 17
18 gfx::Rect KeyboardBoundsFromWindowBounds(const gfx::Rect& window_bounds) {
19 const float kKeyboardHeightRatio = 0.3;
20 return gfx::Rect(
21 window_bounds.x(),
22 window_bounds.y() + window_bounds.height() * (1 - kKeyboardHeightRatio),
23 window_bounds.width(),
24 window_bounds.height() * kKeyboardHeightRatio);
25 }
26
14 // LayoutManager for the virtual keyboard container. Manages a single window 27 // LayoutManager for the virtual keyboard container. Manages a single window
15 // (the virtual keyboard) and keeps it positioned at the bottom of the 28 // (the virtual keyboard) and keeps it positioned at the bottom of the
16 // container window. 29 // container window.
17 class KeyboardLayoutManager : public aura::LayoutManager { 30 class KeyboardLayoutManager : public aura::LayoutManager {
18 public: 31 public:
19 KeyboardLayoutManager(aura::Window* owner, aura::Window* keyboard) 32 KeyboardLayoutManager(aura::Window* owner, aura::Window* keyboard)
20 : owner_(owner), keyboard_(keyboard) {} 33 : owner_(owner), keyboard_(keyboard) {}
21 34
22 // Overridden from aura::LayoutManager 35 // Overridden from aura::LayoutManager
23 virtual void OnWindowResized() OVERRIDE { 36 virtual void OnWindowResized() OVERRIDE {
24 gfx::Rect owner_bounds = owner_->bounds(); 37 SetChildBoundsDirect(keyboard_,
25 gfx::Rect keyboard_bounds = gfx::Rect( 38 KeyboardBoundsFromWindowBounds(owner_->bounds()));
26 owner_bounds.x(),
27 owner_bounds.y() + owner_bounds.height() * 0.7,
28 owner_bounds.width(),
29 owner_bounds.height() * 0.3);
30 SetChildBoundsDirect(keyboard_, keyboard_bounds);
31 } 39 }
32 virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE { 40 virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE {
33 CHECK(child == keyboard_); 41 CHECK(child == keyboard_);
34 } 42 }
35 virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE {} 43 virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE {}
36 virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE {} 44 virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE {}
37 virtual void OnChildWindowVisibilityChanged(aura::Window* child, 45 virtual void OnChildWindowVisibilityChanged(aura::Window* child,
38 bool visible) OVERRIDE {} 46 bool visible) OVERRIDE {}
39 virtual void SetChildBounds(aura::Window* child, 47 virtual void SetChildBounds(aura::Window* child,
40 const gfx::Rect& requested_bounds) OVERRIDE { 48 const gfx::Rect& requested_bounds) OVERRIDE {
41 // Drop these: the size should only be set in OnWindowResized. 49 // Drop these: the size should only be set in OnWindowResized.
42 } 50 }
43 51
44 private: 52 private:
45 aura::Window* owner_; 53 aura::Window* owner_;
46 aura::Window* keyboard_; 54 aura::Window* keyboard_;
47 55
48 DISALLOW_COPY_AND_ASSIGN(KeyboardLayoutManager); 56 DISALLOW_COPY_AND_ASSIGN(KeyboardLayoutManager);
49 }; 57 };
50 58
59 // The KeyboardWindowDelegate makes sure the keyboard-window does not get focus.
60 // This is necessary to make sure that the synthetic key-events reach the target
61 // window.
62 // The delegate deletes itself when the window is destroyed.
63 class KeyboardWindowDelegate : public aura::WindowDelegate {
Ben Goodger (Google) 2013/04/08 21:19:14 this seems kinda heavy handed. is there a way to d
sadrul 2013/04/08 21:27:10 The main necessary bit here is the CanFocus() over
64 public:
65 KeyboardWindowDelegate() {}
66 virtual ~KeyboardWindowDelegate() {}
67
68 private:
69 // Overridden from aura::WindowDelegate:
70 virtual gfx::Size GetMinimumSize() const OVERRIDE { return gfx::Size(); }
71 virtual gfx::Size GetMaximumSize() const OVERRIDE { return gfx::Size(); }
72 virtual void OnBoundsChanged(const gfx::Rect& old_bounds,
73 const gfx::Rect& new_bounds) OVERRIDE {
74 bounds_ = new_bounds;
75 }
76 virtual gfx::NativeCursor GetCursor(const gfx::Point& point) OVERRIDE {
77 return gfx::kNullCursor;
78 }
79 virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE {
80 return HTNOWHERE;
81 }
82 virtual bool ShouldDescendIntoChildForEventHandling(
83 aura::Window* child,
84 const gfx::Point& location) OVERRIDE {
85 return true;
86 }
87 virtual bool CanFocus() OVERRIDE { return false; }
Ben Goodger (Google) 2013/04/08 21:30:06 my next question is... why is it insufficient to r
sadrul 2013/04/08 21:38:53 Right now, we do not use views Widgets for hosting
88 virtual void OnCaptureLost() OVERRIDE {}
89 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {}
90 virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE {}
91 virtual void OnWindowDestroying() OVERRIDE {}
92 virtual void OnWindowDestroyed() OVERRIDE { delete this; }
93 virtual void OnWindowTargetVisibilityChanged(bool visible) OVERRIDE {}
94 virtual bool HasHitTestMask() const OVERRIDE { return true; }
95 virtual void GetHitTestMask(gfx::Path* mask) const OVERRIDE {
96 gfx::Rect keyboard_bounds = KeyboardBoundsFromWindowBounds(bounds_);
97 mask->addRect(RectToSkRect(keyboard_bounds));
98 }
99 virtual scoped_refptr<ui::Texture> CopyTexture() OVERRIDE { return NULL; }
100
101 gfx::Rect bounds_;
102 DISALLOW_COPY_AND_ASSIGN(KeyboardWindowDelegate);
103 };
104
51 } // namespace 105 } // namespace
52 106
53 namespace keyboard { 107 namespace keyboard {
54 108
55 KeyboardController::KeyboardController(KeyboardControllerProxy* proxy) 109 KeyboardController::KeyboardController(KeyboardControllerProxy* proxy)
56 : proxy_(proxy), container_(NULL) { 110 : proxy_(proxy), container_(NULL) {
57 CHECK(proxy); 111 CHECK(proxy);
58 } 112 }
59 113
60 KeyboardController::~KeyboardController() {} 114 KeyboardController::~KeyboardController() {}
61 115
62 aura::Window* KeyboardController::GetContainerWindow() { 116 aura::Window* KeyboardController::GetContainerWindow() {
63 if (!container_) { 117 if (!container_) {
64 container_ = new aura::Window(NULL); 118 container_ = new aura::Window(new KeyboardWindowDelegate());
65 container_->SetName("KeyboardContainer"); 119 container_->SetName("KeyboardContainer");
66 container_->Init(ui::LAYER_NOT_DRAWN); 120 container_->Init(ui::LAYER_NOT_DRAWN);
67 121
68 aura::Window* keyboard = proxy_->GetKeyboardWindow(); 122 aura::Window* keyboard = proxy_->GetKeyboardWindow();
69 keyboard->Show(); 123 keyboard->Show();
70 124
71 container_->SetLayoutManager( 125 container_->SetLayoutManager(
72 new KeyboardLayoutManager(container_, keyboard)); 126 new KeyboardLayoutManager(container_, keyboard));
73 container_->AddChild(keyboard); 127 container_->AddChild(keyboard);
74 } 128 }
75 return container_; 129 return container_;
76 } 130 }
77 131
78 } // namespace keyboard 132 } // namespace keyboard
OLDNEW
« no previous file with comments | « no previous file | ui/keyboard/keyboard_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698