summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorxiyuan@chromium.org <xiyuan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-18 23:30:22 +0000
committerxiyuan@chromium.org <xiyuan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-18 23:30:22 +0000
commitdc57f22b228e6fdf6d64af23f06718cb1e0cb88e (patch)
treec34d27a748f2426b715189548620154a8fa33043 /ui
parent27c84fc7989177d1916e0bd286c6392676648e4b (diff)
downloadchromium_src-dc57f22b228e6fdf6d64af23f06718cb1e0cb88e.zip
chromium_src-dc57f22b228e6fdf6d64af23f06718cb1e0cb88e.tar.gz
chromium_src-dc57f22b228e6fdf6d64af23f06718cb1e0cb88e.tar.bz2
app_list: Use scaled icon for mouse drag.
BUG=117090 TEST=Verify mouse drag shows scaled icon and no two scaled icons are shown by attempting mouse and touch drag at the same time. R=sky@chromium.org Review URL: https://chromiumcodereview.appspot.com/11195044 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@162836 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r--ui/app_list/app_list_item_view.cc72
-rw-r--r--ui/app_list/app_list_item_view.h15
-rw-r--r--ui/app_list/apps_grid_view.h4
3 files changed, 74 insertions, 17 deletions
diff --git a/ui/app_list/app_list_item_view.cc b/ui/app_list/app_list_item_view.cc
index cb7816e..0a14059 100644
--- a/ui/app_list/app_list_item_view.cc
+++ b/ui/app_list/app_list_item_view.cc
@@ -48,6 +48,9 @@ const int kTouchDragStartDelayInMs = 200;
// Scale to transform when touch drag starts.
const float kTouchDraggingScale = 1.5f;
+// Delay in milliseconds of when the dragging UI should be shown for mouse drag.
+const int kMouseDragUIDelayInMs = 100;
+
const gfx::Font& GetTitleFont() {
static gfx::Font* font = NULL;
@@ -75,6 +78,7 @@ AppListItemView::AppListItemView(AppsGridView* apps_grid_view,
apps_grid_view_(apps_grid_view),
icon_(new views::ImageView),
title_(new views::Label),
+ ui_state_(UI_STATE_NORMAL),
touch_dragging_(false) {
icon_->set_interactive(false);
@@ -131,6 +135,30 @@ void AppListItemView::UpdateIcon() {
icon_->SetImage(shadow);
}
+void AppListItemView::SetUIState(UIState state) {
+ if (ui_state_ == state)
+ return;
+
+ ui_state_ = state;
+
+#if !defined(OS_WIN)
+ ui::ScopedLayerAnimationSettings settings(layer()->GetAnimator());
+ switch(ui_state_) {
+ case UI_STATE_NORMAL:
+ title_->SetVisible(true);
+ layer()->SetTransform(gfx::Transform());
+ break;
+ case UI_STATE_DRAGGING:
+ title_->SetVisible(false);
+ const gfx::Rect bounds(layer()->bounds().size());
+ layer()->SetTransform(gfx::GetScaleTransform(
+ bounds.CenterPoint(),
+ kTouchDraggingScale));
+ break;
+ }
+#endif
+}
+
void AppListItemView::OnTouchDragTimer() {
SetTouchDragging(true);
}
@@ -140,20 +168,12 @@ void AppListItemView::SetTouchDragging(bool touch_dragging) {
return;
touch_dragging_ = touch_dragging;
+ SetUIState(touch_dragging_ ? UI_STATE_DRAGGING : UI_STATE_NORMAL);
+}
-#if !defined(OS_WIN)
- ui::ScopedLayerAnimationSettings settings(layer()->GetAnimator());
- if (touch_dragging_) {
- title_->SetVisible(false);
- const gfx::Rect bounds(layer()->bounds().size());
- layer()->SetTransform(gfx::GetScaleTransform(
- bounds.CenterPoint(),
- kTouchDraggingScale));
- } else {
- title_->SetVisible(true);
- layer()->SetTransform(gfx::Transform());
- }
-#endif
+void AppListItemView::OnMouseDragTimer() {
+ DCHECK(apps_grid_view_->IsDraggedView(this));
+ SetUIState(UI_STATE_DRAGGING);
}
void AppListItemView::ItemIconChanged() {
@@ -257,22 +277,40 @@ bool AppListItemView::ShouldEnterPushedState(const ui::Event& event) {
bool AppListItemView::OnMousePressed(const ui::MouseEvent& event) {
CustomButton::OnMousePressed(event);
apps_grid_view_->InitiateDrag(this, AppsGridView::MOUSE, event);
+
+ if (apps_grid_view_->IsDraggedView(this)) {
+ mouse_drag_timer_.Start(FROM_HERE,
+ base::TimeDelta::FromMilliseconds(kMouseDragUIDelayInMs),
+ this, &AppListItemView::OnMouseDragTimer);
+ }
return true;
}
void AppListItemView::OnMouseReleased(const ui::MouseEvent& event) {
CustomButton::OnMouseReleased(event);
apps_grid_view_->EndDrag(false);
+ mouse_drag_timer_.Stop();
+ SetUIState(UI_STATE_NORMAL);
}
void AppListItemView::OnMouseCaptureLost() {
CustomButton::OnMouseCaptureLost();
apps_grid_view_->EndDrag(true);
+ mouse_drag_timer_.Stop();
+ SetUIState(UI_STATE_NORMAL);
}
bool AppListItemView::OnMouseDragged(const ui::MouseEvent& event) {
CustomButton::OnMouseDragged(event);
apps_grid_view_->UpdateDrag(this, AppsGridView::MOUSE, event);
+
+ // Shows dragging UI when it's confirmed without waiting for the timer.
+ if (ui_state_ != UI_STATE_DRAGGING &&
+ apps_grid_view_->dragging() &&
+ apps_grid_view_->IsDraggedView(this)) {
+ mouse_drag_timer_.Stop();
+ SetUIState(UI_STATE_DRAGGING);
+ }
return true;
}
@@ -280,9 +318,11 @@ ui::EventResult AppListItemView::OnGestureEvent(
const ui::GestureEvent& event) {
switch (event.type()) {
case ui::ET_GESTURE_TAP_DOWN:
- touch_drag_timer_.Start(FROM_HERE,
- base::TimeDelta::FromMilliseconds(kTouchDragStartDelayInMs),
- this, &AppListItemView::OnTouchDragTimer);
+ if (!apps_grid_view_->has_dragged_view()) {
+ touch_drag_timer_.Start(FROM_HERE,
+ base::TimeDelta::FromMilliseconds(kTouchDragStartDelayInMs),
+ this, &AppListItemView::OnTouchDragTimer);
+ }
break;
case ui::ET_GESTURE_SCROLL_BEGIN:
if (touch_dragging_) {
diff --git a/ui/app_list/app_list_item_view.h b/ui/app_list/app_list_item_view.h
index 92e90b3..40198ad 100644
--- a/ui/app_list/app_list_item_view.h
+++ b/ui/app_list/app_list_item_view.h
@@ -44,9 +44,16 @@ class APP_LIST_EXPORT AppListItemView : public views::CustomButton,
AppListItemModel* model() const { return model_; }
private:
+ enum UIState {
+ UI_STATE_NORMAL, // Normal UI (icon + label)
+ UI_STATE_DRAGGING, // Dragging UI (scaled icon only)
+ };
+
// Get icon from model and schedule background processing.
void UpdateIcon();
+ void SetUIState(UIState state);
+
// Invoked when |touch_drag_timer_| fires. It sets touch dragging flag so
// that further touch scroll gestures contribute to drag.
void OnTouchDragTimer();
@@ -54,6 +61,9 @@ class APP_LIST_EXPORT AppListItemView : public views::CustomButton,
// Sets |touch_dragging_| flag and updates UI.
void SetTouchDragging(bool touch_dragging);
+ // Invoked when |mouse_drag_timer_| fires to show dragging UI.
+ void OnMouseDragTimer();
+
// AppListItemModelObserver overrides:
virtual void ItemIconChanged() OVERRIDE;
virtual void ItemTitleChanged() OVERRIDE;
@@ -92,6 +102,8 @@ class APP_LIST_EXPORT AppListItemView : public views::CustomButton,
gfx::Size icon_size_;
gfx::ShadowValues icon_shadows_;
+ UIState ui_state_;
+
// A timer to track whether user has pressed on the item long enough. When it
// fires, subsequent scroll gesture events will contribute to drag instead
// scrolling.
@@ -100,6 +112,9 @@ class APP_LIST_EXPORT AppListItemView : public views::CustomButton,
// True if scroll gestures should contribute to dragging.
bool touch_dragging_;
+ // A timer to defer showing drag UI when mouse is pressed.
+ base::OneShotTimer<AppListItemView> mouse_drag_timer_;
+
DISALLOW_COPY_AND_ASSIGN(AppListItemView);
};
diff --git a/ui/app_list/apps_grid_view.h b/ui/app_list/apps_grid_view.h
index 31f1cdd..15907ac 100644
--- a/ui/app_list/apps_grid_view.h
+++ b/ui/app_list/apps_grid_view.h
@@ -74,6 +74,9 @@ class APP_LIST_EXPORT AppsGridView : public views::View,
void EndDrag(bool cancel);
bool IsDraggedView(const views::View* view) const;
+ bool has_dragged_view() const { return drag_view_ != NULL; }
+ bool dragging() const { return drag_pointer_ != NONE; }
+
// Overridden from views::View:
virtual gfx::Size GetPreferredSize() OVERRIDE;
virtual void Layout() OVERRIDE;
@@ -100,7 +103,6 @@ class APP_LIST_EXPORT AppsGridView : public views::View,
};
int tiles_per_page() const { return cols_ * rows_per_page_; }
- bool dragging() const { return drag_pointer_ != NONE; }
// Updates from model.
void Update();