summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/touch
diff options
context:
space:
mode:
authorsadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-16 19:24:22 +0000
committersadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-16 19:24:22 +0000
commit41bdbe34520a8460fa77ab874171eed4cb98cf88 (patch)
tree2d474f85f517e9f677bb9742ab3b5b05c3c7de1d /chrome/browser/ui/touch
parent40e1be3928dc19f05ed53c397ecc1dc77d223c09 (diff)
downloadchromium_src-41bdbe34520a8460fa77ab874171eed4cb98cf88.zip
chromium_src-41bdbe34520a8460fa77ab874171eed4cb98cf88.tar.gz
chromium_src-41bdbe34520a8460fa77ab874171eed4cb98cf88.tar.bz2
keyboard: Slide in and out using transformation
Use some transformation (clip, translate) to show a smoothish slide animation when the keyboard's visibility changes. BUG=none TEST=none Review URL: http://codereview.chromium.org/6499037 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@75158 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/ui/touch')
-rw-r--r--chrome/browser/ui/touch/frame/keyboard_container_view.cc1
-rw-r--r--chrome/browser/ui/touch/frame/touch_browser_frame_view.cc74
-rw-r--r--chrome/browser/ui/touch/frame/touch_browser_frame_view.h14
3 files changed, 70 insertions, 19 deletions
diff --git a/chrome/browser/ui/touch/frame/keyboard_container_view.cc b/chrome/browser/ui/touch/frame/keyboard_container_view.cc
index d11bdfb..6c1cd01 100644
--- a/chrome/browser/ui/touch/frame/keyboard_container_view.cc
+++ b/chrome/browser/ui/touch/frame/keyboard_container_view.cc
@@ -49,4 +49,3 @@ void KeyboardContainerView::ViewHierarchyChanged(bool is_add,
if (is_add)
MakeViewHierarchyUnfocusable(child);
}
-
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 c2d915d..0f8e535 100644
--- a/chrome/browser/ui/touch/frame/touch_browser_frame_view.cc
+++ b/chrome/browser/ui/touch/frame/touch_browser_frame_view.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -16,12 +16,14 @@
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/common/notification_service.h"
#include "chrome/common/notification_type.h"
+#include "ui/base/animation/slide_animation.h"
#include "ui/gfx/rect.h"
#include "views/controls/textfield/textfield.h"
namespace {
const int kKeyboardHeight = 300;
+const int kKeyboardSlideDuration = 500; // In milliseconds
PropertyAccessor<bool>* GetFocusedStateAccessor() {
static PropertyAccessor<bool> state;
@@ -50,6 +52,10 @@ TouchBrowserFrameView::TouchBrowserFrameView(BrowserFrame* frame,
NotificationService::AllSources());
browser_view->browser()->tabstrip_model()->AddObserver(this);
+
+ animation_.reset(new ui::SlideAnimation(this));
+ animation_->SetTweenType(ui::Tween::LINEAR);
+ animation_->SetSlideDuration(kKeyboardSlideDuration);
}
TouchBrowserFrameView::~TouchBrowserFrameView() {
@@ -62,8 +68,17 @@ void TouchBrowserFrameView::Layout() {
if (!keyboard_)
return;
- keyboard_->SetVisible(keyboard_showing_);
- keyboard_->SetBoundsRect(GetBoundsForReservedArea());
+ keyboard_->SetVisible(keyboard_showing_ || animation_->is_animating());
+ gfx::Rect bounds = GetBoundsForReservedArea();
+ if (animation_->is_animating() && !keyboard_showing_) {
+ // The keyboard is in the process of hiding. So pretend it still has the
+ // same bounds as when the keyboard is visible. But
+ // |GetBoundsForReservedArea| should not take this into account so that the
+ // render view gets the entire area to relayout itself.
+ bounds.set_y(bounds.y() - kKeyboardHeight);
+ bounds.set_height(kKeyboardHeight);
+ }
+ keyboard_->SetBoundsRect(bounds);
}
void TouchBrowserFrameView::FocusWillChange(views::View* focused_before,
@@ -79,10 +94,7 @@ void TouchBrowserFrameView::FocusWillChange(views::View* focused_before,
///////////////////////////////////////////////////////////////////////////////
// TouchBrowserFrameView, protected:
int TouchBrowserFrameView::GetReservedHeight() const {
- if (keyboard_showing_)
- return kKeyboardHeight;
-
- return 0;
+ return keyboard_showing_ ? kKeyboardHeight : 0;
}
void TouchBrowserFrameView::ViewHierarchyChanged(bool is_add,
@@ -128,17 +140,19 @@ void TouchBrowserFrameView::UpdateKeyboardAndLayout(bool should_show_keyboard) {
DCHECK(keyboard_);
keyboard_showing_ = should_show_keyboard;
-
- // Because the NonClientFrameView is a sibling of the ClientView, we rely on
- // the parent to resize the ClientView instead of resizing it directly.
- parent()->Layout();
-
- // The keyboard that pops up may end up hiding the text entry. So make sure
- // the renderer scrolls when necessary to keep the textfield visible.
if (keyboard_showing_) {
- RenderViewHost* host =
- browser_view()->browser()->GetSelectedTabContents()->render_view_host();
- host->ScrollFocusedEditableNodeIntoView();
+ animation_->Show();
+
+ // We don't re-layout the client view until the animation ends (see
+ // AnimationEnded below) because we want the client view to occupy the
+ // entire height during the animation.
+ Layout();
+ } else {
+ animation_->Hide();
+
+ browser_view()->set_clip_y(ui::Tween::ValueBetween(
+ animation_->GetCurrentValue(), 0, kKeyboardHeight));
+ parent()->Layout();
}
}
@@ -201,3 +215,29 @@ void TouchBrowserFrameView::Observe(NotificationType type,
Source<TabContents>(source).ptr()->property_bag());
}
}
+
+///////////////////////////////////////////////////////////////////////////////
+// ui::AnimationDelegate implementation
+void TouchBrowserFrameView::AnimationProgressed(const ui::Animation* anim) {
+ keyboard_->SetTranslateY(
+ ui::Tween::ValueBetween(anim->GetCurrentValue(), kKeyboardHeight, 0));
+ browser_view()->set_clip_y(
+ ui::Tween::ValueBetween(anim->GetCurrentValue(), 0, kKeyboardHeight));
+ SchedulePaint();
+}
+
+void TouchBrowserFrameView::AnimationEnded(const ui::Animation* animation) {
+ browser_view()->set_clip_y(0);
+ if (keyboard_showing_) {
+ // Because the NonClientFrameView is a sibling of the ClientView, we rely on
+ // the parent to resize the ClientView instead of resizing it directly.
+ parent()->Layout();
+
+ // The keyboard that pops up may end up hiding the text entry. So make sure
+ // the renderer scrolls when necessary to keep the textfield visible.
+ RenderViewHost* host =
+ browser_view()->browser()->GetSelectedTabContents()->render_view_host();
+ host->ScrollFocusedEditableNodeIntoView();
+ }
+ SchedulePaint();
+}
diff --git a/chrome/browser/ui/touch/frame/touch_browser_frame_view.h b/chrome/browser/ui/touch/frame/touch_browser_frame_view.h
index e5700f4..7eb49b0 100644
--- a/chrome/browser/ui/touch/frame/touch_browser_frame_view.h
+++ b/chrome/browser/ui/touch/frame/touch_browser_frame_view.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -10,6 +10,7 @@
#include "chrome/browser/tabs/tab_strip_model_observer.h"
#include "chrome/common/notification_observer.h"
#include "chrome/common/notification_registrar.h"
+#include "ui/base/animation/animation_delegate.h"
#include "views/focus/focus_manager.h"
class BrowserFrame;
@@ -18,9 +19,14 @@ class KeyboardContainerView;
class NotificationDetails;
class NotificationSource;
+namespace ui {
+class SlideAnimation;
+}
+
class TouchBrowserFrameView : public OpaqueBrowserFrameView,
public views::FocusChangeListener,
public TabStripModelObserver,
+ public ui::AnimationDelegate,
public NotificationObserver {
public:
enum VirtualKeyboardType {
@@ -61,11 +67,17 @@ class TouchBrowserFrameView : public OpaqueBrowserFrameView,
const NotificationSource& source,
const NotificationDetails& details);
+ // Overridden from ui::AnimationDelegate:
+ virtual void AnimationProgressed(const ui::Animation* animation);
+ virtual void AnimationEnded(const ui::Animation* animation);
+
bool keyboard_showing_;
bool focus_listener_added_;
KeyboardContainerView* keyboard_;
NotificationRegistrar registrar_;
+ scoped_ptr<ui::SlideAnimation> animation_;
+
DISALLOW_COPY_AND_ASSIGN(TouchBrowserFrameView);
};