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 <sstream> | 5 #include <sstream> |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
538 | 538 |
539 *rect = gfx::Rect(win_rect); | 539 *rect = gfx::Rect(win_rect); |
540 return true; | 540 return true; |
541 } | 541 } |
542 | 542 |
543 // Used to position the view relative to a point, which requires |anchor| to be | 543 // Used to position the view relative to a point, which requires |anchor| to be |
544 // in the center of the desired view location. This helper function updates | 544 // in the center of the desired view location. This helper function updates |
545 // |anchor| thus, using the location of the point in |point|, the distance | 545 // |anchor| thus, using the location of the point in |point|, the distance |
546 // to move the view from |point| in |offset|, and the direction to move | 546 // to move the view from |point| in |offset|, and the direction to move |
547 // represented in |direction|. | 547 // represented in |direction|. |
548 // The function will also ensure the view is within |offset| of the screen | |
549 // edges. | |
548 // To position relative to a screen corner, the absolute values of |direction|.x | 550 // To position relative to a screen corner, the absolute values of |direction|.x |
549 // and |direction.y| should both be 1. To position relative to some point on the | 551 // and |direction.y| should both be 1. To position relative to some point on the |
550 // taskbar, one of the absolute values of |direction.x| and |direction.y| should | 552 // taskbar, one of the absolute values of |direction.x| and |direction.y| should |
551 // be 1 and the other 0. | 553 // be 1 and the other 0. |
552 void FloatFromPoint(const gfx::Point& point, | 554 void FloatFromPoint(const gfx::Point& point, |
553 const gfx::Size& offset, | 555 const gfx::Size& offset, |
554 const gfx::Point& direction, | 556 const gfx::Point& direction, |
557 const gfx::Rect& screen_rect, | |
tapted
2013/02/27 08:41:59
bounds_rect, Then,
| |
555 gfx::Point* anchor) { | 558 gfx::Point* anchor) { |
556 anchor->set_x(point.x() + direction.x() * offset.width()); | 559 anchor->set_x(point.x() + direction.x() * offset.width()); |
557 anchor->set_y(point.y() + direction.y() * offset.height()); | 560 anchor->set_y(point.y() + direction.y() * offset.height()); |
561 | |
562 if (anchor->x() - offset.width() < screen_rect.x()) | |
tapted
2013/02/27 08:41:59
I think these 11 lines can be just
anchor.ClampTo
| |
563 anchor->set_x(screen_rect.x() + offset.width()); | |
564 | |
565 if (anchor->x() + offset.width() > screen_rect.right()) | |
566 anchor->set_x(screen_rect.right() - offset.width()); | |
567 | |
568 if (anchor->y() - offset.height() < screen_rect.y()) | |
569 anchor->set_y(screen_rect.y() + offset.height()); | |
570 | |
571 if (anchor->y() + offset.height() > screen_rect.bottom()) | |
572 anchor->set_y(screen_rect.bottom() - offset.height()); | |
558 } | 573 } |
559 | 574 |
560 void AppListController::SnapArrowLocationToTaskbarEdge( | 575 void AppListController::SnapArrowLocationToTaskbarEdge( |
561 const gfx::Display& display, | 576 const gfx::Display& display, |
562 gfx::Point* anchor) { | 577 gfx::Point* anchor) { |
563 const int kSnapDistance = 50; | 578 const int kSnapDistance = 50; |
564 const int kSnapOffset = 5; | 579 const int kSnapOffset = 5; |
565 | 580 |
566 gfx::Rect taskbar_rect; | 581 gfx::Rect taskbar_rect; |
567 gfx::Size float_offset = current_view_->GetPreferredSize(); | 582 gfx::Size float_offset = current_view_->GetPreferredSize(); |
568 float_offset.set_width(float_offset.width() / 2); | 583 float_offset.set_width(float_offset.width() / 2); |
569 float_offset.set_height(float_offset.height() / 2); | 584 float_offset.set_height(float_offset.height() / 2); |
570 float_offset.Enlarge(kSnapOffset, kSnapOffset); | 585 float_offset.Enlarge(kSnapOffset, kSnapOffset); |
tapted
2013/02/27 08:42:30
[ I think with this Enlarge, it also gets a margin
| |
571 | 586 |
587 const gfx::Rect& screen_rect = display.bounds(); | |
tapted
2013/02/27 08:41:59
With
gfx::Rect& bounds_rect = display.bounds();
b
tapted
2013/02/27 08:41:59
Does it need to take into account the taskbar, to
| |
588 | |
572 // If we can't find the taskbar, snap to the bottom left. | 589 // If we can't find the taskbar, snap to the bottom left. |
573 // If the display size is the same as the work area, and does not contain the | 590 // If the display size is the same as the work area, and does not contain the |
574 // taskbar, either the taskbar is hidden or on another monitor, so just snap | 591 // taskbar, either the taskbar is hidden or on another monitor, so just snap |
575 // to the bottom left. | 592 // to the bottom left. |
576 if (!GetTaskbarRect(&taskbar_rect) || | 593 if (!GetTaskbarRect(&taskbar_rect) || |
577 (display.work_area() == display.bounds() && | 594 (display.work_area() == display.bounds() && |
578 !display.work_area().Contains(taskbar_rect))) { | 595 !display.work_area().Contains(taskbar_rect))) { |
579 FloatFromPoint(display.work_area().bottom_left(), | 596 FloatFromPoint(display.work_area().bottom_left(), |
580 float_offset, | 597 float_offset, |
581 gfx::Point(1, -1), | 598 gfx::Point(1, -1), |
599 screen_rect, | |
582 anchor); | 600 anchor); |
583 return; | 601 return; |
584 } | 602 } |
585 | 603 |
586 const gfx::Rect& screen_rect = display.bounds(); | |
587 | |
588 // Snap to the taskbar edge. If the cursor is greater than kSnapDistance away, | 604 // Snap to the taskbar edge. If the cursor is greater than kSnapDistance away, |
589 // also move to the left (for horizontal taskbars) or top (for vertical). | 605 // also move to the left (for horizontal taskbars) or top (for vertical). |
590 | 606 |
591 // First handle taskbar on bottom. | 607 // First handle taskbar on bottom. |
592 if (taskbar_rect.width() == screen_rect.width()) { | 608 if (taskbar_rect.width() == screen_rect.width()) { |
593 if (taskbar_rect.bottom() == screen_rect.bottom()) { | 609 if (taskbar_rect.bottom() == screen_rect.bottom()) { |
594 if (taskbar_rect.y() - anchor->y() > kSnapDistance) { | 610 if (taskbar_rect.y() - anchor->y() > kSnapDistance) { |
595 FloatFromPoint(gfx::Point(screen_rect.x(), taskbar_rect.y()), | 611 FloatFromPoint(gfx::Point(screen_rect.x(), taskbar_rect.y()), |
596 float_offset, | 612 float_offset, |
597 gfx::Point(1, -1), | 613 gfx::Point(1, -1), |
614 screen_rect, | |
598 anchor); | 615 anchor); |
599 return; | 616 return; |
600 } | 617 } |
601 | 618 |
602 FloatFromPoint(gfx::Point(anchor->x(), taskbar_rect.y()), | 619 FloatFromPoint(gfx::Point(anchor->x(), taskbar_rect.y()), |
603 float_offset, | 620 float_offset, |
604 gfx::Point(0, -1), | 621 gfx::Point(0, -1), |
622 screen_rect, | |
605 anchor); | 623 anchor); |
606 return; | 624 return; |
607 } | 625 } |
608 | 626 |
609 // Now try on the top. | 627 // Now try on the top. |
610 if (anchor->y() - taskbar_rect.bottom() > kSnapDistance) { | 628 if (anchor->y() - taskbar_rect.bottom() > kSnapDistance) { |
611 FloatFromPoint(gfx::Point(screen_rect.x(), taskbar_rect.bottom()), | 629 FloatFromPoint(gfx::Point(screen_rect.x(), taskbar_rect.bottom()), |
612 float_offset, | 630 float_offset, |
613 gfx::Point(1, 1), | 631 gfx::Point(1, 1), |
632 screen_rect, | |
614 anchor); | 633 anchor); |
615 return; | 634 return; |
616 } | 635 } |
617 | 636 |
618 FloatFromPoint(gfx::Point(anchor->x(), taskbar_rect.bottom()), | 637 FloatFromPoint(gfx::Point(anchor->x(), taskbar_rect.bottom()), |
619 float_offset, | 638 float_offset, |
620 gfx::Point(0, 1), | 639 gfx::Point(0, 1), |
640 screen_rect, | |
621 anchor); | 641 anchor); |
622 return; | 642 return; |
623 } | 643 } |
624 | 644 |
625 // Now try the left. | 645 // Now try the left. |
626 if (taskbar_rect.x() == screen_rect.x()) { | 646 if (taskbar_rect.x() == screen_rect.x()) { |
627 if (anchor->x() - taskbar_rect.right() > kSnapDistance) { | 647 if (anchor->x() - taskbar_rect.right() > kSnapDistance) { |
628 FloatFromPoint(gfx::Point(taskbar_rect.right(), screen_rect.y()), | 648 FloatFromPoint(gfx::Point(taskbar_rect.right(), screen_rect.y()), |
629 float_offset, | 649 float_offset, |
630 gfx::Point(1, 1), | 650 gfx::Point(1, 1), |
651 screen_rect, | |
631 anchor); | 652 anchor); |
632 return; | 653 return; |
633 } | 654 } |
634 | 655 |
635 FloatFromPoint(gfx::Point(taskbar_rect.right(), anchor->y()), | 656 FloatFromPoint(gfx::Point(taskbar_rect.right(), anchor->y()), |
636 float_offset, | 657 float_offset, |
637 gfx::Point(1, 0), | 658 gfx::Point(1, 0), |
659 screen_rect, | |
638 anchor); | 660 anchor); |
639 return; | 661 return; |
640 } | 662 } |
641 | 663 |
642 // Finally, try the right. | 664 // Finally, try the right. |
643 if (taskbar_rect.x() - anchor->x() > kSnapDistance) { | 665 if (taskbar_rect.x() - anchor->x() > kSnapDistance) { |
644 FloatFromPoint(gfx::Point(taskbar_rect.x(), screen_rect.y()), | 666 FloatFromPoint(gfx::Point(taskbar_rect.x(), screen_rect.y()), |
645 float_offset, | 667 float_offset, |
646 gfx::Point(-1, 1), | 668 gfx::Point(-1, 1), |
669 screen_rect, | |
647 anchor); | 670 anchor); |
648 return; | 671 return; |
649 } | 672 } |
650 | 673 |
651 FloatFromPoint(gfx::Point(taskbar_rect.x(), anchor->y()), | 674 FloatFromPoint(gfx::Point(taskbar_rect.x(), anchor->y()), |
652 float_offset, | 675 float_offset, |
653 gfx::Point(-1, 0), | 676 gfx::Point(-1, 0), |
677 screen_rect, | |
654 anchor); | 678 anchor); |
655 } | 679 } |
656 | 680 |
657 void AppListController::UpdateArrowPositionAndAnchorPoint( | 681 void AppListController::UpdateArrowPositionAndAnchorPoint( |
658 const gfx::Point& cursor) { | 682 const gfx::Point& cursor) { |
659 gfx::Point anchor(cursor); | 683 gfx::Point anchor(cursor); |
660 gfx::Screen* screen = | 684 gfx::Screen* screen = |
661 gfx::Screen::GetScreenFor(current_view_->GetWidget()->GetNativeView()); | 685 gfx::Screen::GetScreenFor(current_view_->GetWidget()->GetNativeView()); |
662 gfx::Display display = screen->GetDisplayNearestPoint(anchor); | 686 gfx::Display display = screen->GetDisplayNearestPoint(anchor); |
663 | 687 |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
875 | 899 |
876 Profile* GetCurrentAppListProfile() { | 900 Profile* GetCurrentAppListProfile() { |
877 return GetCurrentAppListController()->profile(); | 901 return GetCurrentAppListController()->profile(); |
878 } | 902 } |
879 | 903 |
880 bool IsAppListVisible() { | 904 bool IsAppListVisible() { |
881 return GetCurrentAppListController()->IsAppListVisible(); | 905 return GetCurrentAppListController()->IsAppListVisible(); |
882 } | 906 } |
883 | 907 |
884 } // namespace chrome | 908 } // namespace chrome |
OLD | NEW |