OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/app_list/views/app_list_item_view.h" | 5 #include "ui/app_list/views/app_list_item_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "grit/ui_resources.h" | 10 #include "grit/ui_resources.h" |
11 #include "ui/app_list/app_list_constants.h" | 11 #include "ui/app_list/app_list_constants.h" |
12 #include "ui/app_list/app_list_item_model.h" | 12 #include "ui/app_list/app_list_item_model.h" |
13 #include "ui/app_list/views/apps_grid_view.h" | 13 #include "ui/app_list/views/apps_grid_view.h" |
14 #include "ui/app_list/views/cached_label.h" | 14 #include "ui/app_list/views/cached_label.h" |
15 #include "ui/base/accessibility/accessible_view_state.h" | 15 #include "ui/base/accessibility/accessible_view_state.h" |
16 #include "ui/base/animation/throb_animation.h" | 16 #include "ui/base/animation/throb_animation.h" |
17 #include "ui/base/dragdrop/drag_utils.h" | |
17 #include "ui/base/resource/resource_bundle.h" | 18 #include "ui/base/resource/resource_bundle.h" |
18 #include "ui/compositor/layer.h" | 19 #include "ui/compositor/layer.h" |
19 #include "ui/compositor/scoped_layer_animation_settings.h" | 20 #include "ui/compositor/scoped_layer_animation_settings.h" |
20 #include "ui/gfx/canvas.h" | 21 #include "ui/gfx/canvas.h" |
21 #include "ui/gfx/font.h" | 22 #include "ui/gfx/font.h" |
22 #include "ui/gfx/image/image_skia_operations.h" | 23 #include "ui/gfx/image/image_skia_operations.h" |
23 #include "ui/gfx/transform_util.h" | 24 #include "ui/gfx/transform_util.h" |
24 #include "ui/views/controls/image_view.h" | 25 #include "ui/views/controls/image_view.h" |
25 #include "ui/views/controls/label.h" | 26 #include "ui/views/controls/label.h" |
26 #include "ui/views/controls/menu/menu_item_view.h" | 27 #include "ui/views/controls/menu/menu_item_view.h" |
27 #include "ui/views/controls/menu/menu_runner.h" | 28 #include "ui/views/controls/menu/menu_runner.h" |
29 #include "ui/views/drag_controller.h" | |
28 | 30 |
29 namespace app_list { | 31 namespace app_list { |
30 | 32 |
31 namespace { | 33 namespace { |
32 | 34 |
33 const int kTopBottomPadding = 10; | 35 const int kTopBottomPadding = 10; |
34 const int kTopPadding = 20; | 36 const int kTopPadding = 20; |
35 const int kIconTitleSpacing = 7; | 37 const int kIconTitleSpacing = 7; |
36 const int kProgressBarHorizontalPadding = 12; | 38 const int kProgressBarHorizontalPadding = 12; |
37 const int kProgressBarVerticalPadding = 4; | 39 const int kProgressBarVerticalPadding = 4; |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
165 | 167 |
166 void AppListItemView::OnMouseDragTimer() { | 168 void AppListItemView::OnMouseDragTimer() { |
167 DCHECK(apps_grid_view_->IsDraggedView(this)); | 169 DCHECK(apps_grid_view_->IsDraggedView(this)); |
168 SetUIState(UI_STATE_DRAGGING); | 170 SetUIState(UI_STATE_DRAGGING); |
169 } | 171 } |
170 | 172 |
171 void AppListItemView::Prerender() { | 173 void AppListItemView::Prerender() { |
172 title_->PaintToBackingImage(); | 174 title_->PaintToBackingImage(); |
173 } | 175 } |
174 | 176 |
177 gfx::ImageSkia AppListItemView::GetDragImage() { | |
178 gfx::Canvas canvas(size(), ui::SCALE_FACTOR_100P, false /* is_opaque */); | |
179 gfx::Rect bounds(0, 0, size().width(), size().height()); | |
xiyuan
2013/06/19 05:41:38
nit: gfx::Rect bounds(size);
koz (OOO until 15th September)
2013/06/19 07:55:08
Done.
| |
180 LOG(ERROR) << bounds.ToString(); | |
xiyuan
2013/06/19 05:41:38
Get rid of debugging log.
koz (OOO until 15th September)
2013/06/19 07:55:08
Done.
| |
181 canvas.FillRect(bounds, SkColorSetARGB(0, 0, 0, 0), | |
182 SkXfermode::kSrc_Mode); | |
xiyuan
2013/06/19 05:41:38
nit: canvas.DrawColor(SK_ColorTRANSPARENT);
koz (OOO until 15th September)
2013/06/19 07:55:08
Done.
| |
183 PaintChildren(&canvas); | |
184 | |
185 return gfx::ImageSkia(canvas.ExtractImageRep()); | |
186 } | |
187 | |
175 void AppListItemView::ItemIconChanged() { | 188 void AppListItemView::ItemIconChanged() { |
176 UpdateIcon(); | 189 UpdateIcon(); |
177 } | 190 } |
178 | 191 |
179 void AppListItemView::ItemTitleChanged() { | 192 void AppListItemView::ItemTitleChanged() { |
180 title_->SetText(UTF8ToUTF16(model_->title())); | 193 title_->SetText(UTF8ToUTF16(model_->title())); |
181 title_->Invalidate(); | 194 title_->Invalidate(); |
182 Layout(); | 195 Layout(); |
183 } | 196 } |
184 | 197 |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
334 return CustomButton::OnKeyPressed(event); | 347 return CustomButton::OnKeyPressed(event); |
335 } | 348 } |
336 | 349 |
337 void AppListItemView::OnMouseReleased(const ui::MouseEvent& event) { | 350 void AppListItemView::OnMouseReleased(const ui::MouseEvent& event) { |
338 CustomButton::OnMouseReleased(event); | 351 CustomButton::OnMouseReleased(event); |
339 apps_grid_view_->EndDrag(false); | 352 apps_grid_view_->EndDrag(false); |
340 mouse_drag_timer_.Stop(); | 353 mouse_drag_timer_.Stop(); |
341 SetUIState(UI_STATE_NORMAL); | 354 SetUIState(UI_STATE_NORMAL); |
342 } | 355 } |
343 | 356 |
344 void AppListItemView::OnMouseCaptureLost() { | |
xiyuan
2013/06/19 05:41:38
Why don't we need this?
koz (OOO until 15th September)
2013/06/19 07:55:08
Ah, we do on CROS, but it causes problems on Windo
| |
345 CustomButton::OnMouseCaptureLost(); | |
346 apps_grid_view_->EndDrag(true); | |
347 mouse_drag_timer_.Stop(); | |
348 SetUIState(UI_STATE_NORMAL); | |
349 } | |
350 | |
351 bool AppListItemView::OnMouseDragged(const ui::MouseEvent& event) { | 357 bool AppListItemView::OnMouseDragged(const ui::MouseEvent& event) { |
352 CustomButton::OnMouseDragged(event); | 358 CustomButton::OnMouseDragged(event); |
353 apps_grid_view_->UpdateDrag(this, AppsGridView::MOUSE, event); | 359 apps_grid_view_->UpdateDragFromItem(AppsGridView::MOUSE, event); |
354 | 360 |
355 // Shows dragging UI when it's confirmed without waiting for the timer. | 361 // Shows dragging UI when it's confirmed without waiting for the timer. |
356 if (ui_state_ != UI_STATE_DRAGGING && | 362 if (ui_state_ != UI_STATE_DRAGGING && |
357 apps_grid_view_->dragging() && | 363 apps_grid_view_->dragging() && |
358 apps_grid_view_->IsDraggedView(this)) { | 364 apps_grid_view_->IsDraggedView(this)) { |
359 mouse_drag_timer_.Stop(); | 365 mouse_drag_timer_.Stop(); |
360 SetUIState(UI_STATE_DRAGGING); | 366 SetUIState(UI_STATE_DRAGGING); |
361 } | 367 } |
362 return true; | 368 return true; |
363 } | 369 } |
364 | 370 |
365 void AppListItemView::OnGestureEvent(ui::GestureEvent* event) { | 371 void AppListItemView::OnGestureEvent(ui::GestureEvent* event) { |
366 switch (event->type()) { | 372 switch (event->type()) { |
367 case ui::ET_GESTURE_SCROLL_BEGIN: | 373 case ui::ET_GESTURE_SCROLL_BEGIN: |
368 if (touch_dragging_) { | 374 if (touch_dragging_) { |
369 apps_grid_view_->InitiateDrag(this, AppsGridView::TOUCH, *event); | 375 apps_grid_view_->InitiateDrag(this, AppsGridView::TOUCH, *event); |
370 event->SetHandled(); | 376 event->SetHandled(); |
371 } | 377 } |
372 break; | 378 break; |
373 case ui::ET_GESTURE_SCROLL_UPDATE: | 379 case ui::ET_GESTURE_SCROLL_UPDATE: |
374 if (touch_dragging_) { | 380 if (touch_dragging_) { |
375 apps_grid_view_->UpdateDrag(this, AppsGridView::TOUCH, *event); | 381 apps_grid_view_->UpdateDragFromItem(AppsGridView::TOUCH, *event); |
376 event->SetHandled(); | 382 event->SetHandled(); |
377 } | 383 } |
378 break; | 384 break; |
379 case ui::ET_GESTURE_SCROLL_END: | 385 case ui::ET_GESTURE_SCROLL_END: |
380 case ui::ET_SCROLL_FLING_START: | 386 case ui::ET_SCROLL_FLING_START: |
381 if (touch_dragging_) { | 387 if (touch_dragging_) { |
382 SetTouchDragging(false); | 388 SetTouchDragging(false); |
383 apps_grid_view_->EndDrag(false); | 389 apps_grid_view_->EndDrag(false); |
384 event->SetHandled(); | 390 event->SetHandled(); |
385 } | 391 } |
386 break; | 392 break; |
387 case ui::ET_GESTURE_LONG_PRESS: | 393 case ui::ET_GESTURE_LONG_PRESS: |
388 if (!apps_grid_view_->has_dragged_view()) | 394 if (!apps_grid_view_->has_dragged_view()) |
389 SetTouchDragging(true); | 395 SetTouchDragging(true); |
390 event->SetHandled(); | 396 event->SetHandled(); |
391 break; | 397 break; |
392 case ui::ET_GESTURE_LONG_TAP: | 398 case ui::ET_GESTURE_LONG_TAP: |
393 case ui::ET_GESTURE_END: | 399 case ui::ET_GESTURE_END: |
394 if (touch_dragging_) | 400 if (touch_dragging_) |
395 SetTouchDragging(false); | 401 SetTouchDragging(false); |
396 break; | 402 break; |
397 default: | 403 default: |
398 break; | 404 break; |
399 } | 405 } |
400 if (!event->handled()) | 406 if (!event->handled()) |
401 CustomButton::OnGestureEvent(event); | 407 CustomButton::OnGestureEvent(event); |
402 } | 408 } |
403 | 409 |
404 } // namespace app_list | 410 } // namespace app_list |
OLD | NEW |