Commit 4829dd90 authored by mukai@chromium.org's avatar mukai@chromium.org

Move HomeCard to avoid virtual keyboard when it's shown.

BUG=386652
R=sadrul@chromium.org, oshima@chromium.org
TBR=kevers@chromium.org
TEST=manually

Review URL: https://codereview.chromium.org/356263003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@282081 0039d316-1c4b-4281-b951-d872f2087c98
parent 7adb26a7
...@@ -26,6 +26,11 @@ class HomeCardLayoutManager : public aura::LayoutManager { ...@@ -26,6 +26,11 @@ class HomeCardLayoutManager : public aura::LayoutManager {
: container_(container) {} : container_(container) {}
virtual ~HomeCardLayoutManager() {} virtual ~HomeCardLayoutManager() {}
void UpdateVirtualKeyboardBounds(const gfx::Rect& bounds) {
virtual_keyboard_bounds_ = bounds;
Layout();
}
private: private:
// aura::LayoutManager: // aura::LayoutManager:
virtual void OnWindowResized() OVERRIDE { Layout(); } virtual void OnWindowResized() OVERRIDE { Layout(); }
...@@ -55,7 +60,10 @@ class HomeCardLayoutManager : public aura::LayoutManager { ...@@ -55,7 +60,10 @@ class HomeCardLayoutManager : public aura::LayoutManager {
aura::Window* home_card = container_->children()[0]; aura::Window* home_card = container_->children()[0];
if (!home_card->IsVisible()) if (!home_card->IsVisible())
return; return;
gfx::Rect screen_bounds = home_card->GetRootWindow()->bounds(); gfx::Rect screen_bounds = home_card->GetRootWindow()->bounds();
if (!virtual_keyboard_bounds_.IsEmpty())
screen_bounds.set_height(virtual_keyboard_bounds_.y());
gfx::Rect card_bounds = screen_bounds; gfx::Rect card_bounds = screen_bounds;
card_bounds.Inset(kHomeCardHorizontalMargin, card_bounds.Inset(kHomeCardHorizontalMargin,
screen_bounds.height() - kHomeCardHeight, screen_bounds.height() - kHomeCardHeight,
...@@ -66,6 +74,7 @@ class HomeCardLayoutManager : public aura::LayoutManager { ...@@ -66,6 +74,7 @@ class HomeCardLayoutManager : public aura::LayoutManager {
} }
aura::Window* container_; aura::Window* container_;
gfx::Rect virtual_keyboard_bounds_;
DISALLOW_COPY_AND_ASSIGN(HomeCardLayoutManager); DISALLOW_COPY_AND_ASSIGN(HomeCardLayoutManager);
}; };
...@@ -86,6 +95,8 @@ class HomeCardImpl : public HomeCard, public AcceleratorHandler { ...@@ -86,6 +95,8 @@ class HomeCardImpl : public HomeCard, public AcceleratorHandler {
// Overridden from HomeCard: // Overridden from HomeCard:
virtual void RegisterSearchProvider( virtual void RegisterSearchProvider(
app_list::SearchProvider* search_provider) OVERRIDE; app_list::SearchProvider* search_provider) OVERRIDE;
virtual void UpdateVirtualKeyboardBounds(
const gfx::Rect& bounds) OVERRIDE;
// AcceleratorHandler: // AcceleratorHandler:
virtual bool IsCommandEnabled(int command_id) const OVERRIDE { return true; } virtual bool IsCommandEnabled(int command_id) const OVERRIDE { return true; }
...@@ -103,6 +114,7 @@ class HomeCardImpl : public HomeCard, public AcceleratorHandler { ...@@ -103,6 +114,7 @@ class HomeCardImpl : public HomeCard, public AcceleratorHandler {
views::Widget* home_card_widget_; views::Widget* home_card_widget_;
AppListViewDelegate* view_delegate_; AppListViewDelegate* view_delegate_;
HomeCardLayoutManager* layout_manager_;
// Right now HomeCard allows only one search provider. // Right now HomeCard allows only one search provider.
// TODO(mukai): port app-list's SearchController and Mixer. // TODO(mukai): port app-list's SearchController and Mixer.
...@@ -113,7 +125,8 @@ class HomeCardImpl : public HomeCard, public AcceleratorHandler { ...@@ -113,7 +125,8 @@ class HomeCardImpl : public HomeCard, public AcceleratorHandler {
HomeCardImpl::HomeCardImpl(AppModelBuilder* model_builder) HomeCardImpl::HomeCardImpl(AppModelBuilder* model_builder)
: model_builder_(model_builder), : model_builder_(model_builder),
home_card_widget_(NULL) { home_card_widget_(NULL),
layout_manager_(NULL) {
DCHECK(!instance); DCHECK(!instance);
instance = this; instance = this;
} }
...@@ -132,12 +145,18 @@ void HomeCardImpl::RegisterSearchProvider( ...@@ -132,12 +145,18 @@ void HomeCardImpl::RegisterSearchProvider(
view_delegate_->RegisterSearchProvider(search_provider_.get()); view_delegate_->RegisterSearchProvider(search_provider_.get());
} }
void HomeCardImpl::UpdateVirtualKeyboardBounds(
const gfx::Rect& bounds) {
layout_manager_->UpdateVirtualKeyboardBounds(bounds);
}
void HomeCardImpl::Init() { void HomeCardImpl::Init() {
InstallAccelerators(); InstallAccelerators();
aura::Window* container = aura::Window* container =
ScreenManager::Get()->CreateContainer("HomeCardContainer"); ScreenManager::Get()->CreateContainer("HomeCardContainer");
container->SetLayoutManager(new HomeCardLayoutManager(container)); layout_manager_ = new HomeCardLayoutManager(container);
container->SetLayoutManager(layout_manager_);
wm::SetChildWindowVisibilityChangesAnimated(container); wm::SetChildWindowVisibilityChangesAnimated(container);
view_delegate_ = new AppListViewDelegate(model_builder_.get()); view_delegate_ = new AppListViewDelegate(model_builder_.get());
......
...@@ -11,6 +11,10 @@ namespace app_list { ...@@ -11,6 +11,10 @@ namespace app_list {
class SearchProvider; class SearchProvider;
} }
namespace gfx {
class Rect;
}
namespace athena { namespace athena {
class AppModelBuilder; class AppModelBuilder;
...@@ -28,6 +32,10 @@ class ATHENA_EXPORT HomeCard { ...@@ -28,6 +32,10 @@ class ATHENA_EXPORT HomeCard {
// the ownership of the specified provider. // the ownership of the specified provider.
virtual void RegisterSearchProvider( virtual void RegisterSearchProvider(
app_list::SearchProvider* search_provider) = 0; app_list::SearchProvider* search_provider) = 0;
// Called when the virtual keyboard changed has changed to |bounds|.
virtual void UpdateVirtualKeyboardBounds(
const gfx::Rect& bounds) = 0;
}; };
} // namespace athena } // namespace athena
......
...@@ -14,6 +14,7 @@ include_rules = [ ...@@ -14,6 +14,7 @@ include_rules = [
"+ui/compositor", "+ui/compositor",
"+ui/events", "+ui/events",
"+ui/gl", "+ui/gl",
"+ui/keyboard",
"+ui/wm/core", "+ui/wm/core",
] ]
......
...@@ -24,6 +24,8 @@ ...@@ -24,6 +24,8 @@
#include "content/public/app/content_main.h" #include "content/public/app/content_main.h"
#include "ui/aura/window_tree_host.h" #include "ui/aura/window_tree_host.h"
#include "ui/base/resource/resource_bundle.h" #include "ui/base/resource/resource_bundle.h"
#include "ui/keyboard/keyboard_controller.h"
#include "ui/keyboard/keyboard_controller_observer.h"
#include "ui/wm/core/visibility_controller.h" #include "ui/wm/core/visibility_controller.h"
namespace { namespace {
...@@ -34,6 +36,27 @@ const char kDefaultAppPath[] = ...@@ -34,6 +36,27 @@ const char kDefaultAppPath[] =
"chrome/common/extensions/docs/examples/apps/calculator/app"; "chrome/common/extensions/docs/examples/apps/calculator/app";
} // namespace } // namespace
// This class observes the change of the virtual keyboard and distribute the
// change to appropriate modules of athena.
// TODO(oshima): move the VK bounds logic to screen manager.
class VirtualKeyboardObserver : public keyboard::KeyboardControllerObserver {
public:
VirtualKeyboardObserver() {
keyboard::KeyboardController::GetInstance()->AddObserver(this);
}
virtual ~VirtualKeyboardObserver() {
keyboard::KeyboardController::GetInstance()->RemoveObserver(this);
}
private:
virtual void OnKeyboardBoundsChanging(const gfx::Rect& new_bounds) OVERRIDE {
athena::HomeCard::Get()->UpdateVirtualKeyboardBounds(new_bounds);
}
DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardObserver);
};
class AthenaBrowserMainDelegate : public apps::ShellBrowserMainDelegate { class AthenaBrowserMainDelegate : public apps::ShellBrowserMainDelegate {
public: public:
AthenaBrowserMainDelegate() {} AthenaBrowserMainDelegate() {}
...@@ -62,12 +85,16 @@ class AthenaBrowserMainDelegate : public apps::ShellBrowserMainDelegate { ...@@ -62,12 +85,16 @@ class AthenaBrowserMainDelegate : public apps::ShellBrowserMainDelegate {
athena::HomeCard::Get()->RegisterSearchProvider( athena::HomeCard::Get()->RegisterSearchProvider(
new athena::UrlSearchProvider(context)); new athena::UrlSearchProvider(context));
athena::VirtualKeyboardManager::Create(context); athena::VirtualKeyboardManager::Create(context);
keyboard_observer_.reset(new VirtualKeyboardObserver());
CreateTestPages(context); CreateTestPages(context);
CreateDebugWindow(); CreateDebugWindow();
} }
virtual void Shutdown() OVERRIDE { athena::ShutdownAthena(); } virtual void Shutdown() OVERRIDE {
keyboard_observer_.reset();
athena::ShutdownAthena();
}
virtual apps::ShellDesktopController* CreateDesktopController() OVERRIDE { virtual apps::ShellDesktopController* CreateDesktopController() OVERRIDE {
// TODO(mukai): create Athena's own ShellDesktopController subclass so that // TODO(mukai): create Athena's own ShellDesktopController subclass so that
...@@ -78,6 +105,8 @@ class AthenaBrowserMainDelegate : public apps::ShellBrowserMainDelegate { ...@@ -78,6 +105,8 @@ class AthenaBrowserMainDelegate : public apps::ShellBrowserMainDelegate {
} }
private: private:
scoped_ptr<VirtualKeyboardObserver> keyboard_observer_;
DISALLOW_COPY_AND_ASSIGN(AthenaBrowserMainDelegate); DISALLOW_COPY_AND_ASSIGN(AthenaBrowserMainDelegate);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment