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

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

Issue 2206033002: mash: Migrate ash::DragImageView to wm common types (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nits Created 4 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/drag_drop/drag_image_view.cc ('k') | no next file » | 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 #include <memory> 8 #include <memory>
9 9
10 #include "ash/aura/wm_window_aura.h"
11 #include "ash/common/ash_constants.h" 10 #include "ash/common/ash_constants.h"
12 #include "ash/common/ash_switches.h" 11 #include "ash/common/ash_switches.h"
12 #include "ash/common/drag_drop/drag_image_view.h"
13 #include "ash/common/scoped_root_window_for_new_windows.h" 13 #include "ash/common/scoped_root_window_for_new_windows.h"
14 #include "ash/common/shelf/app_list_button.h" 14 #include "ash/common/shelf/app_list_button.h"
15 #include "ash/common/shelf/overflow_bubble.h" 15 #include "ash/common/shelf/overflow_bubble.h"
16 #include "ash/common/shelf/overflow_bubble_view.h" 16 #include "ash/common/shelf/overflow_bubble_view.h"
17 #include "ash/common/shelf/overflow_button.h" 17 #include "ash/common/shelf/overflow_button.h"
18 #include "ash/common/shelf/shelf_button.h" 18 #include "ash/common/shelf/shelf_button.h"
19 #include "ash/common/shelf/shelf_constants.h" 19 #include "ash/common/shelf/shelf_constants.h"
20 #include "ash/common/shelf/shelf_delegate.h" 20 #include "ash/common/shelf/shelf_delegate.h"
21 #include "ash/common/shelf/shelf_menu_model.h" 21 #include "ash/common/shelf/shelf_menu_model.h"
22 #include "ash/common/shelf/shelf_model.h" 22 #include "ash/common/shelf/shelf_model.h"
23 #include "ash/common/shelf/wm_shelf.h" 23 #include "ash/common/shelf/wm_shelf.h"
24 #include "ash/common/shell_delegate.h" 24 #include "ash/common/shell_delegate.h"
25 #include "ash/common/wm/root_window_finder.h" 25 #include "ash/common/wm/root_window_finder.h"
26 #include "ash/common/wm_lookup.h" 26 #include "ash/common/wm_lookup.h"
27 #include "ash/common/wm_shell.h" 27 #include "ash/common/wm_shell.h"
28 #include "ash/drag_drop/drag_image_view.h" 28 #include "ash/common/wm_window.h"
29 #include "ash/shelf/shelf.h" 29 #include "ash/shelf/shelf.h"
30 #include "ash/shelf/shelf_icon_observer.h" 30 #include "ash/shelf/shelf_icon_observer.h"
31 #include "ash/shelf/shelf_widget.h" 31 #include "ash/shelf/shelf_widget.h"
32 #include "base/auto_reset.h" 32 #include "base/auto_reset.h"
33 #include "base/metrics/histogram.h" 33 #include "base/metrics/histogram.h"
34 #include "grit/ash_strings.h" 34 #include "grit/ash_strings.h"
35 #include "ui/accessibility/ax_view_state.h" 35 #include "ui/accessibility/ax_view_state.h"
36 #include "ui/aura/window.h" 36 #include "ui/aura/window.h"
37 #include "ui/base/l10n/l10n_util.h" 37 #include "ui/base/l10n/l10n_util.h"
38 #include "ui/base/models/simple_menu_model.h" 38 #include "ui/base/models/simple_menu_model.h"
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 return this; 568 return this;
569 } 569 }
570 570
571 void ShelfView::CreateDragIconProxy( 571 void ShelfView::CreateDragIconProxy(
572 const gfx::Point& location_in_screen_coordinates, 572 const gfx::Point& location_in_screen_coordinates,
573 const gfx::ImageSkia& icon, 573 const gfx::ImageSkia& icon,
574 views::View* replaced_view, 574 views::View* replaced_view,
575 const gfx::Vector2d& cursor_offset_from_center, 575 const gfx::Vector2d& cursor_offset_from_center,
576 float scale_factor) { 576 float scale_factor) {
577 drag_replaced_view_ = replaced_view; 577 drag_replaced_view_ = replaced_view;
578 WmWindow* root_window =
579 WmLookup::Get()
580 ->GetWindowForWidget(drag_replaced_view_->GetWidget())
581 ->GetRootWindow();
578 drag_image_.reset(new DragImageView( 582 drag_image_.reset(new DragImageView(
579 drag_replaced_view_->GetWidget()->GetNativeWindow()->GetRootWindow(), 583 root_window, ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE));
580 ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE));
581 drag_image_->SetImage(icon); 584 drag_image_->SetImage(icon);
582 gfx::Size size = drag_image_->GetPreferredSize(); 585 gfx::Size size = drag_image_->GetPreferredSize();
583 size.set_width(size.width() * scale_factor); 586 size.set_width(size.width() * scale_factor);
584 size.set_height(size.height() * scale_factor); 587 size.set_height(size.height() * scale_factor);
585 drag_image_offset_ = gfx::Vector2d(size.width() / 2, size.height() / 2) + 588 drag_image_offset_ = gfx::Vector2d(size.width() / 2, size.height() / 2) +
586 cursor_offset_from_center; 589 cursor_offset_from_center;
587 gfx::Rect drag_image_bounds( 590 gfx::Rect drag_image_bounds(
588 location_in_screen_coordinates - drag_image_offset_, size); 591 location_in_screen_coordinates - drag_image_offset_, size);
589 drag_image_->SetBoundsInScreen(drag_image_bounds); 592 drag_image_->SetBoundsInScreen(drag_image_bounds);
590 drag_image_->SetWidgetVisible(true); 593 drag_image_->SetWidgetVisible(true);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 643
641 // Since there is already an icon presented by the caller, we hide this item 644 // Since there is already an icon presented by the caller, we hide this item
642 // for now. That has to be done by reducing the size since the visibility will 645 // for now. That has to be done by reducing the size since the visibility will
643 // change once a regrouping animation is performed. 646 // change once a regrouping animation is performed.
644 pre_drag_and_drop_size_ = drag_and_drop_view->size(); 647 pre_drag_and_drop_size_ = drag_and_drop_view->size();
645 drag_and_drop_view->SetSize(gfx::Size()); 648 drag_and_drop_view->SetSize(gfx::Size());
646 649
647 // First we have to center the mouse cursor over the item. 650 // First we have to center the mouse cursor over the item.
648 gfx::Point pt = drag_and_drop_view->GetBoundsInScreen().CenterPoint(); 651 gfx::Point pt = drag_and_drop_view->GetBoundsInScreen().CenterPoint();
649 views::View::ConvertPointFromScreen(drag_and_drop_view, &pt); 652 views::View::ConvertPointFromScreen(drag_and_drop_view, &pt);
650 gfx::Point point_in_root = location_in_screen_coordinates; 653 gfx::Point point_in_root =
651 ::wm::ConvertPointFromScreen( 654 wm::GetRootWindowAt(location_in_screen_coordinates)
652 WmWindowAura::GetAuraWindow( 655 ->ConvertPointFromScreen(location_in_screen_coordinates);
653 ash::wm::GetRootWindowAt(location_in_screen_coordinates)),
654 &point_in_root);
655 ui::MouseEvent event(ui::ET_MOUSE_PRESSED, pt, point_in_root, 656 ui::MouseEvent event(ui::ET_MOUSE_PRESSED, pt, point_in_root,
656 ui::EventTimeForNow(), 0, 0); 657 ui::EventTimeForNow(), 0, 0);
657 PointerPressedOnButton(drag_and_drop_view, DRAG_AND_DROP, event); 658 PointerPressedOnButton(drag_and_drop_view, DRAG_AND_DROP, event);
658 659
659 // Drag the item where it really belongs. 660 // Drag the item where it really belongs.
660 Drag(location_in_screen_coordinates); 661 Drag(location_in_screen_coordinates);
661 return true; 662 return true;
662 } 663 }
663 664
664 bool ShelfView::Drag(const gfx::Point& location_in_screen_coordinates) { 665 bool ShelfView::Drag(const gfx::Point& location_in_screen_coordinates) {
665 if (!drag_and_drop_shelf_id_ || 666 if (!drag_and_drop_shelf_id_ ||
666 !GetBoundsInScreen().Contains(location_in_screen_coordinates)) 667 !GetBoundsInScreen().Contains(location_in_screen_coordinates))
667 return false; 668 return false;
668 669
669 gfx::Point pt = location_in_screen_coordinates; 670 gfx::Point pt = location_in_screen_coordinates;
670 views::View* drag_and_drop_view = 671 views::View* drag_and_drop_view =
671 view_model_->view_at(model_->ItemIndexByID(drag_and_drop_shelf_id_)); 672 view_model_->view_at(model_->ItemIndexByID(drag_and_drop_shelf_id_));
672 ConvertPointFromScreen(drag_and_drop_view, &pt); 673 ConvertPointFromScreen(drag_and_drop_view, &pt);
673 gfx::Point point_in_root = location_in_screen_coordinates; 674 gfx::Point point_in_root =
674 ::wm::ConvertPointFromScreen( 675 wm::GetRootWindowAt(location_in_screen_coordinates)
675 WmWindowAura::GetAuraWindow( 676 ->ConvertPointFromScreen(location_in_screen_coordinates);
676 ash::wm::GetRootWindowAt(location_in_screen_coordinates)),
677 &point_in_root);
678 ui::MouseEvent event(ui::ET_MOUSE_DRAGGED, pt, point_in_root, 677 ui::MouseEvent event(ui::ET_MOUSE_DRAGGED, pt, point_in_root,
679 ui::EventTimeForNow(), 0, 0); 678 ui::EventTimeForNow(), 0, 0);
680 PointerDraggedOnButton(drag_and_drop_view, DRAG_AND_DROP, event); 679 PointerDraggedOnButton(drag_and_drop_view, DRAG_AND_DROP, event);
681 return true; 680 return true;
682 } 681 }
683 682
684 void ShelfView::EndDrag(bool cancel) { 683 void ShelfView::EndDrag(bool cancel) {
685 if (!drag_and_drop_shelf_id_) 684 if (!drag_and_drop_shelf_id_)
686 return; 685 return;
687 686
(...skipping 1229 matching lines...) Expand 10 before | Expand all | Expand 10 after
1917 1916
1918 int ShelfView::CalculateShelfDistance(const gfx::Point& coordinate) const { 1917 int ShelfView::CalculateShelfDistance(const gfx::Point& coordinate) const {
1919 const gfx::Rect bounds = GetBoundsInScreen(); 1918 const gfx::Rect bounds = GetBoundsInScreen();
1920 int distance = shelf_->SelectValueForShelfAlignment( 1919 int distance = shelf_->SelectValueForShelfAlignment(
1921 bounds.y() - coordinate.y(), coordinate.x() - bounds.right(), 1920 bounds.y() - coordinate.y(), coordinate.x() - bounds.right(),
1922 bounds.x() - coordinate.x()); 1921 bounds.x() - coordinate.x());
1923 return distance > 0 ? distance : 0; 1922 return distance > 0 ? distance : 0;
1924 } 1923 }
1925 1924
1926 } // namespace ash 1925 } // namespace ash
OLDNEW
« no previous file with comments | « ash/drag_drop/drag_image_view.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698