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

Side by Side Diff: ash/shelf/shelf_view.cc

Issue 425363002: Moving coordinate conversion methods from ash/wm to ui/wm. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More fixes Created 6 years, 4 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
« no previous file with comments | « ash/shelf/shelf_bezel_event_filter.cc ('k') | ash/shelf/shelf_view_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "ash/shelf/shelf_view.h" 5 #include "ash/shelf/shelf_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "ash/ash_constants.h" 9 #include "ash/ash_constants.h"
10 #include "ash/ash_switches.h" 10 #include "ash/ash_switches.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 #include "ui/gfx/point.h" 48 #include "ui/gfx/point.h"
49 #include "ui/views/animation/bounds_animator.h" 49 #include "ui/views/animation/bounds_animator.h"
50 #include "ui/views/border.h" 50 #include "ui/views/border.h"
51 #include "ui/views/controls/button/image_button.h" 51 #include "ui/views/controls/button/image_button.h"
52 #include "ui/views/controls/menu/menu_model_adapter.h" 52 #include "ui/views/controls/menu/menu_model_adapter.h"
53 #include "ui/views/controls/menu/menu_runner.h" 53 #include "ui/views/controls/menu/menu_runner.h"
54 #include "ui/views/focus/focus_search.h" 54 #include "ui/views/focus/focus_search.h"
55 #include "ui/views/view_model.h" 55 #include "ui/views/view_model.h"
56 #include "ui/views/view_model_utils.h" 56 #include "ui/views/view_model_utils.h"
57 #include "ui/views/widget/widget.h" 57 #include "ui/views/widget/widget.h"
58 #include "ui/wm/core/coordinate_conversion.h"
58 59
59 using gfx::Animation; 60 using gfx::Animation;
60 using views::View; 61 using views::View;
61 62
62 namespace ash { 63 namespace ash {
63 64
64 const int SHELF_ALIGNMENT_UMA_ENUM_VALUE_BOTTOM = 0; 65 const int SHELF_ALIGNMENT_UMA_ENUM_VALUE_BOTTOM = 0;
65 const int SHELF_ALIGNMENT_UMA_ENUM_VALUE_LEFT = 1; 66 const int SHELF_ALIGNMENT_UMA_ENUM_VALUE_LEFT = 1;
66 const int SHELF_ALIGNMENT_UMA_ENUM_VALUE_RIGHT = 2; 67 const int SHELF_ALIGNMENT_UMA_ENUM_VALUE_RIGHT = 2;
67 const int SHELF_ALIGNMENT_UMA_ENUM_VALUE_COUNT = 3; 68 const int SHELF_ALIGNMENT_UMA_ENUM_VALUE_COUNT = 3;
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 // Since there is already an icon presented by the caller, we hide this item 611 // Since there is already an icon presented by the caller, we hide this item
611 // for now. That has to be done by reducing the size since the visibility will 612 // for now. That has to be done by reducing the size since the visibility will
612 // change once a regrouping animation is performed. 613 // change once a regrouping animation is performed.
613 pre_drag_and_drop_size_ = drag_and_drop_view->size(); 614 pre_drag_and_drop_size_ = drag_and_drop_view->size();
614 drag_and_drop_view->SetSize(gfx::Size()); 615 drag_and_drop_view->SetSize(gfx::Size());
615 616
616 // First we have to center the mouse cursor over the item. 617 // First we have to center the mouse cursor over the item.
617 gfx::Point pt = drag_and_drop_view->GetBoundsInScreen().CenterPoint(); 618 gfx::Point pt = drag_and_drop_view->GetBoundsInScreen().CenterPoint();
618 views::View::ConvertPointFromScreen(drag_and_drop_view, &pt); 619 views::View::ConvertPointFromScreen(drag_and_drop_view, &pt);
619 gfx::Point point_in_root = location_in_screen_coordinates; 620 gfx::Point point_in_root = location_in_screen_coordinates;
620 ash::wm::ConvertPointFromScreen( 621 ::wm::ConvertPointFromScreen(
621 ash::wm::GetRootWindowAt(location_in_screen_coordinates), 622 ash::wm::GetRootWindowAt(location_in_screen_coordinates), &point_in_root);
622 &point_in_root);
623 ui::MouseEvent event(ui::ET_MOUSE_PRESSED, pt, point_in_root, 0, 0); 623 ui::MouseEvent event(ui::ET_MOUSE_PRESSED, pt, point_in_root, 0, 0);
624 PointerPressedOnButton(drag_and_drop_view, 624 PointerPressedOnButton(drag_and_drop_view,
625 ShelfButtonHost::DRAG_AND_DROP, 625 ShelfButtonHost::DRAG_AND_DROP,
626 event); 626 event);
627 627
628 // Drag the item where it really belongs. 628 // Drag the item where it really belongs.
629 Drag(location_in_screen_coordinates); 629 Drag(location_in_screen_coordinates);
630 return true; 630 return true;
631 } 631 }
632 632
633 bool ShelfView::Drag(const gfx::Point& location_in_screen_coordinates) { 633 bool ShelfView::Drag(const gfx::Point& location_in_screen_coordinates) {
634 if (!drag_and_drop_shelf_id_ || 634 if (!drag_and_drop_shelf_id_ ||
635 !GetBoundsInScreen().Contains(location_in_screen_coordinates)) 635 !GetBoundsInScreen().Contains(location_in_screen_coordinates))
636 return false; 636 return false;
637 637
638 gfx::Point pt = location_in_screen_coordinates; 638 gfx::Point pt = location_in_screen_coordinates;
639 views::View* drag_and_drop_view = view_model_->view_at( 639 views::View* drag_and_drop_view = view_model_->view_at(
640 model_->ItemIndexByID(drag_and_drop_shelf_id_)); 640 model_->ItemIndexByID(drag_and_drop_shelf_id_));
641 ConvertPointFromScreen(drag_and_drop_view, &pt); 641 ConvertPointFromScreen(drag_and_drop_view, &pt);
642 gfx::Point point_in_root = location_in_screen_coordinates; 642 gfx::Point point_in_root = location_in_screen_coordinates;
643 ash::wm::ConvertPointFromScreen( 643 ::wm::ConvertPointFromScreen(
644 ash::wm::GetRootWindowAt(location_in_screen_coordinates), 644 ash::wm::GetRootWindowAt(location_in_screen_coordinates), &point_in_root);
645 &point_in_root);
646 ui::MouseEvent event(ui::ET_MOUSE_DRAGGED, pt, point_in_root, 0, 0); 645 ui::MouseEvent event(ui::ET_MOUSE_DRAGGED, pt, point_in_root, 0, 0);
647 PointerDraggedOnButton(drag_and_drop_view, 646 PointerDraggedOnButton(drag_and_drop_view,
648 ShelfButtonHost::DRAG_AND_DROP, 647 ShelfButtonHost::DRAG_AND_DROP,
649 event); 648 event);
650 return true; 649 return true;
651 } 650 }
652 651
653 void ShelfView::EndDrag(bool cancel) { 652 void ShelfView::EndDrag(bool cancel) {
654 if (!drag_and_drop_shelf_id_) 653 if (!drag_and_drop_shelf_id_)
655 return; 654 return;
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
1003 bounds_animator_->StopAnimatingView(drag_view_); 1002 bounds_animator_->StopAnimatingView(drag_view_);
1004 } 1003 }
1005 1004
1006 bool ShelfView::HandleRipOffDrag(const ui::LocatedEvent& event) { 1005 bool ShelfView::HandleRipOffDrag(const ui::LocatedEvent& event) {
1007 int current_index = view_model_->GetIndexOfView(drag_view_); 1006 int current_index = view_model_->GetIndexOfView(drag_view_);
1008 DCHECK_NE(-1, current_index); 1007 DCHECK_NE(-1, current_index);
1009 std::string dragged_app_id = 1008 std::string dragged_app_id =
1010 delegate_->GetAppIDForShelfID(model_->items()[current_index].id); 1009 delegate_->GetAppIDForShelfID(model_->items()[current_index].id);
1011 1010
1012 gfx::Point screen_location = event.root_location(); 1011 gfx::Point screen_location = event.root_location();
1013 ash::wm::ConvertPointToScreen(GetWidget()->GetNativeWindow()->GetRootWindow(), 1012 ::wm::ConvertPointToScreen(GetWidget()->GetNativeWindow()->GetRootWindow(),
1014 &screen_location); 1013 &screen_location);
1015 1014
1016 // To avoid ugly forwards and backwards flipping we use different constants 1015 // To avoid ugly forwards and backwards flipping we use different constants
1017 // for ripping off / re-inserting the items. 1016 // for ripping off / re-inserting the items.
1018 if (dragged_off_shelf_) { 1017 if (dragged_off_shelf_) {
1019 // If the shelf/overflow bubble bounds contains |screen_location| we insert 1018 // If the shelf/overflow bubble bounds contains |screen_location| we insert
1020 // the item back into the shelf. 1019 // the item back into the shelf.
1021 if (GetBoundsForDragInsertInScreen().Contains(screen_location)) { 1020 if (GetBoundsForDragInsertInScreen().Contains(screen_location)) {
1022 if (dragged_off_from_overflow_to_shelf_) { 1021 if (dragged_off_from_overflow_to_shelf_) {
1023 // During the dragging an item from Shelf to Overflow, it can enter here 1022 // During the dragging an item from Shelf to Overflow, it can enter here
1024 // directly because both are located very closly. 1023 // directly because both are located very closly.
(...skipping 893 matching lines...) Expand 10 before | Expand all | Expand 10 after
1918 distance = bounds.x() - coordinate.x(); 1917 distance = bounds.x() - coordinate.x();
1919 break; 1918 break;
1920 case SHELF_ALIGNMENT_TOP: 1919 case SHELF_ALIGNMENT_TOP:
1921 distance = coordinate.y() - bounds.bottom(); 1920 distance = coordinate.y() - bounds.bottom();
1922 break; 1921 break;
1923 } 1922 }
1924 return distance > 0 ? distance : 0; 1923 return distance > 0 ? distance : 0;
1925 } 1924 }
1926 1925
1927 } // namespace ash 1926 } // namespace ash
OLDNEW
« no previous file with comments | « ash/shelf/shelf_bezel_event_filter.cc ('k') | ash/shelf/shelf_view_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698