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

Side by Side Diff: athena/home/home_card_impl.cc

Issue 356263003: Move HomeCard to avoid virtual keyboard when it's shown. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | athena/home/public/home_card.h » ('j') | athena/main/athena_main.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "athena/home/public/home_card.h" 5 #include "athena/home/public/home_card.h"
6 6
7 #include "athena/home/app_list_view_delegate.h" 7 #include "athena/home/app_list_view_delegate.h"
8 #include "athena/home/public/app_model_builder.h" 8 #include "athena/home/public/app_model_builder.h"
9 #include "athena/input/public/accelerator_manager.h" 9 #include "athena/input/public/accelerator_manager.h"
10 #include "athena/screen/public/screen_manager.h" 10 #include "athena/screen/public/screen_manager.h"
11 #include "ui/app_list/search_provider.h" 11 #include "ui/app_list/search_provider.h"
12 #include "ui/app_list/views/app_list_view.h" 12 #include "ui/app_list/views/app_list_view.h"
13 #include "ui/aura/layout_manager.h" 13 #include "ui/aura/layout_manager.h"
14 #include "ui/aura/window.h" 14 #include "ui/aura/window.h"
15 #include "ui/wm/core/visibility_controller.h" 15 #include "ui/wm/core/visibility_controller.h"
16 #include "ui/wm/core/window_animations.h" 16 #include "ui/wm/core/window_animations.h"
17 17
18 namespace athena { 18 namespace athena {
19 namespace { 19 namespace {
20 20
21 HomeCard* instance = NULL; 21 HomeCard* instance = NULL;
22 22
23 class HomeCardLayoutManager : public aura::LayoutManager { 23 class HomeCardLayoutManager : public aura::LayoutManager {
24 public: 24 public:
25 explicit HomeCardLayoutManager(aura::Window* container) 25 explicit HomeCardLayoutManager(aura::Window* container)
26 : container_(container) {} 26 : container_(container) {}
27 virtual ~HomeCardLayoutManager() {} 27 virtual ~HomeCardLayoutManager() {}
28 28
29 void UpdateVirtualKeyboardBounds(const gfx::Rect& bounds) {
30 virtual_keyboard_bounds_ = bounds;
31 Layout();
32 }
33
29 private: 34 private:
30 // aura::LayoutManager: 35 // aura::LayoutManager:
31 virtual void OnWindowResized() OVERRIDE { Layout(); } 36 virtual void OnWindowResized() OVERRIDE { Layout(); }
32 virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE { Layout(); } 37 virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE { Layout(); }
33 virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE {} 38 virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE {}
34 virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE { 39 virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE {
35 Layout(); 40 Layout();
36 } 41 }
37 virtual void OnChildWindowVisibilityChanged(aura::Window* child, 42 virtual void OnChildWindowVisibilityChanged(aura::Window* child,
38 bool visible) OVERRIDE { 43 bool visible) OVERRIDE {
39 Layout(); 44 Layout();
40 } 45 }
41 virtual void SetChildBounds(aura::Window* child, 46 virtual void SetChildBounds(aura::Window* child,
42 const gfx::Rect& requested_bounds) OVERRIDE { 47 const gfx::Rect& requested_bounds) OVERRIDE {
43 SetChildBoundsDirect(child, gfx::Rect(requested_bounds.size())); 48 SetChildBoundsDirect(child, gfx::Rect(requested_bounds.size()));
44 } 49 }
45 50
46 void Layout() { 51 void Layout() {
47 const int kHomeCardHeight = 150; 52 const int kHomeCardHeight = 150;
48 const int kHomeCardHorizontalMargin = 50; 53 const int kHomeCardHorizontalMargin = 50;
49 // Currently the home card is provided as a bubble and the bounds has to be 54 // Currently the home card is provided as a bubble and the bounds has to be
50 // increased to cancel the shadow. 55 // increased to cancel the shadow.
51 // TODO(mukai): stops using the bubble and remove this. 56 // TODO(mukai): stops using the bubble and remove this.
52 const int kHomeCardShadowWidth = 30; 57 const int kHomeCardShadowWidth = 30;
53 if (container_->children().size() < 1) 58 if (container_->children().size() < 1)
54 return; 59 return;
55 aura::Window* home_card = container_->children()[0]; 60 aura::Window* home_card = container_->children()[0];
56 if (!home_card->IsVisible()) 61 if (!home_card->IsVisible())
57 return; 62 return;
63
58 gfx::Rect screen_bounds = home_card->GetRootWindow()->bounds(); 64 gfx::Rect screen_bounds = home_card->GetRootWindow()->bounds();
65 if (!virtual_keyboard_bounds_.IsEmpty())
66 screen_bounds.set_height(virtual_keyboard_bounds_.y());
59 gfx::Rect card_bounds = screen_bounds; 67 gfx::Rect card_bounds = screen_bounds;
60 card_bounds.Inset(kHomeCardHorizontalMargin, 68 card_bounds.Inset(kHomeCardHorizontalMargin,
61 screen_bounds.height() - kHomeCardHeight, 69 screen_bounds.height() - kHomeCardHeight,
62 kHomeCardHorizontalMargin, 70 kHomeCardHorizontalMargin,
63 0); 71 0);
64 card_bounds.Inset(-kHomeCardShadowWidth, -kHomeCardShadowWidth); 72 card_bounds.Inset(-kHomeCardShadowWidth, -kHomeCardShadowWidth);
65 SetChildBoundsDirect(home_card, card_bounds); 73 SetChildBoundsDirect(home_card, card_bounds);
66 } 74 }
67 75
68 aura::Window* container_; 76 aura::Window* container_;
77 gfx::Rect virtual_keyboard_bounds_;
69 78
70 DISALLOW_COPY_AND_ASSIGN(HomeCardLayoutManager); 79 DISALLOW_COPY_AND_ASSIGN(HomeCardLayoutManager);
71 }; 80 };
72 81
73 class HomeCardImpl : public HomeCard, public AcceleratorHandler { 82 class HomeCardImpl : public HomeCard, public AcceleratorHandler {
74 public: 83 public:
75 explicit HomeCardImpl(AppModelBuilder* model_builder); 84 explicit HomeCardImpl(AppModelBuilder* model_builder);
76 virtual ~HomeCardImpl(); 85 virtual ~HomeCardImpl();
77 86
78 void Init(); 87 void Init();
79 88
80 private: 89 private:
81 enum Command { 90 enum Command {
82 COMMAND_SHOW_HOME_CARD, 91 COMMAND_SHOW_HOME_CARD,
83 }; 92 };
84 void InstallAccelerators(); 93 void InstallAccelerators();
85 94
86 // Overridden from HomeCard: 95 // Overridden from HomeCard:
87 virtual void RegisterSearchProvider( 96 virtual void RegisterSearchProvider(
88 app_list::SearchProvider* search_provider) OVERRIDE; 97 app_list::SearchProvider* search_provider) OVERRIDE;
98 virtual void UpdateVirtualKeyboardBounds(
99 const gfx::Rect& bounds) OVERRIDE;
89 100
90 // AcceleratorHandler: 101 // AcceleratorHandler:
91 virtual bool IsCommandEnabled(int command_id) const OVERRIDE { return true; } 102 virtual bool IsCommandEnabled(int command_id) const OVERRIDE { return true; }
92 virtual bool OnAcceleratorFired(int command_id, 103 virtual bool OnAcceleratorFired(int command_id,
93 const ui::Accelerator& accelerator) OVERRIDE { 104 const ui::Accelerator& accelerator) OVERRIDE {
94 DCHECK_EQ(COMMAND_SHOW_HOME_CARD, command_id); 105 DCHECK_EQ(COMMAND_SHOW_HOME_CARD, command_id);
95 if (home_card_widget_->IsVisible()) 106 if (home_card_widget_->IsVisible())
96 home_card_widget_->Hide(); 107 home_card_widget_->Hide();
97 else 108 else
98 home_card_widget_->Show(); 109 home_card_widget_->Show();
99 return true; 110 return true;
100 } 111 }
101 112
102 scoped_ptr<AppModelBuilder> model_builder_; 113 scoped_ptr<AppModelBuilder> model_builder_;
103 114
104 views::Widget* home_card_widget_; 115 views::Widget* home_card_widget_;
105 AppListViewDelegate* view_delegate_; 116 AppListViewDelegate* view_delegate_;
117 HomeCardLayoutManager* layout_manager_;
106 118
107 // Right now HomeCard allows only one search provider. 119 // Right now HomeCard allows only one search provider.
108 // TODO(mukai): port app-list's SearchController and Mixer. 120 // TODO(mukai): port app-list's SearchController and Mixer.
109 scoped_ptr<app_list::SearchProvider> search_provider_; 121 scoped_ptr<app_list::SearchProvider> search_provider_;
110 122
111 DISALLOW_COPY_AND_ASSIGN(HomeCardImpl); 123 DISALLOW_COPY_AND_ASSIGN(HomeCardImpl);
112 }; 124 };
113 125
114 HomeCardImpl::HomeCardImpl(AppModelBuilder* model_builder) 126 HomeCardImpl::HomeCardImpl(AppModelBuilder* model_builder)
115 : model_builder_(model_builder), 127 : model_builder_(model_builder),
116 home_card_widget_(NULL) { 128 home_card_widget_(NULL),
129 layout_manager_(NULL) {
117 DCHECK(!instance); 130 DCHECK(!instance);
118 instance = this; 131 instance = this;
119 } 132 }
120 133
121 HomeCardImpl::~HomeCardImpl() { 134 HomeCardImpl::~HomeCardImpl() {
122 DCHECK(instance); 135 DCHECK(instance);
123 home_card_widget_->CloseNow(); 136 home_card_widget_->CloseNow();
124 view_delegate_ = NULL; 137 view_delegate_ = NULL;
125 instance = NULL; 138 instance = NULL;
126 } 139 }
127 140
128 void HomeCardImpl::RegisterSearchProvider( 141 void HomeCardImpl::RegisterSearchProvider(
129 app_list::SearchProvider* search_provider) { 142 app_list::SearchProvider* search_provider) {
130 DCHECK(!search_provider_); 143 DCHECK(!search_provider_);
131 search_provider_.reset(search_provider); 144 search_provider_.reset(search_provider);
132 view_delegate_->RegisterSearchProvider(search_provider_.get()); 145 view_delegate_->RegisterSearchProvider(search_provider_.get());
133 } 146 }
134 147
148 void HomeCardImpl::UpdateVirtualKeyboardBounds(
149 const gfx::Rect& bounds) {
150 layout_manager_->UpdateVirtualKeyboardBounds(bounds);
151 }
152
135 void HomeCardImpl::Init() { 153 void HomeCardImpl::Init() {
136 InstallAccelerators(); 154 InstallAccelerators();
137 155
138 aura::Window* container = 156 aura::Window* container =
139 ScreenManager::Get()->CreateContainer("HomeCardContainer"); 157 ScreenManager::Get()->CreateContainer("HomeCardContainer");
140 container->SetLayoutManager(new HomeCardLayoutManager(container)); 158 layout_manager_ = new HomeCardLayoutManager(container);
159 container->SetLayoutManager(layout_manager_);
141 wm::SetChildWindowVisibilityChangesAnimated(container); 160 wm::SetChildWindowVisibilityChangesAnimated(container);
142 161
143 view_delegate_ = new AppListViewDelegate(model_builder_.get()); 162 view_delegate_ = new AppListViewDelegate(model_builder_.get());
144 if (search_provider_) 163 if (search_provider_)
145 view_delegate_->RegisterSearchProvider(search_provider_.get()); 164 view_delegate_->RegisterSearchProvider(search_provider_.get());
146 app_list::AppListView* view = new app_list::AppListView(view_delegate_); 165 app_list::AppListView* view = new app_list::AppListView(view_delegate_);
147 view->InitAsBubbleAtFixedLocation( 166 view->InitAsBubbleAtFixedLocation(
148 container, 167 container,
149 0 /* initial_apps_page */, 168 0 /* initial_apps_page */,
150 gfx::Point(), 169 gfx::Point(),
(...skipping 28 matching lines...) Expand all
179 instance = NULL; 198 instance = NULL;
180 } 199 }
181 200
182 // static 201 // static
183 HomeCard* HomeCard::Get() { 202 HomeCard* HomeCard::Get() {
184 DCHECK(instance); 203 DCHECK(instance);
185 return instance; 204 return instance;
186 } 205 }
187 206
188 } // namespace athena 207 } // namespace athena
OLDNEW
« no previous file with comments | « no previous file | athena/home/public/home_card.h » ('j') | athena/main/athena_main.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698