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 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 void IncrementPendingProfileLoads(); | 188 void IncrementPendingProfileLoads(); |
189 void DecrementPendingProfileLoads(); | 189 void DecrementPendingProfileLoads(); |
190 | 190 |
191 // Create or recreate, and initialize |current_view_| from |profile|. | 191 // Create or recreate, and initialize |current_view_| from |profile|. |
192 void PopulateViewFromProfile(Profile* profile); | 192 void PopulateViewFromProfile(Profile* profile); |
193 | 193 |
194 // Save |profile_file_path| as the app list profile in local state. | 194 // Save |profile_file_path| as the app list profile in local state. |
195 void SaveProfilePathToLocalState(const base::FilePath& profile_file_path); | 195 void SaveProfilePathToLocalState(const base::FilePath& profile_file_path); |
196 | 196 |
197 // Utility methods for showing the app list. | 197 // Utility methods for showing the app list. |
198 void SnapArrowLocationToTaskbarEdge( | 198 gfx::Point FindAnchorPoint(const gfx::Display& display, |
199 const gfx::Display& display, | 199 const gfx::Point& cursor); |
200 gfx::Point* anchor); | |
201 void UpdateArrowPositionAndAnchorPoint(const gfx::Point& cursor); | 200 void UpdateArrowPositionAndAnchorPoint(const gfx::Point& cursor); |
202 string16 GetAppListIconPath(); | 201 string16 GetAppListIconPath(); |
203 | 202 |
204 // Check if the app list or the taskbar has focus. The app list is kept | 203 // Check if the app list or the taskbar has focus. The app list is kept |
205 // visible whenever either of these have focus, which allows it to be | 204 // visible whenever either of these have focus, which allows it to be |
206 // pinned but will hide it if it otherwise loses focus. This is checked | 205 // pinned but will hide it if it otherwise loses focus. This is checked |
207 // periodically whenever the app list does not have focus. | 206 // periodically whenever the app list does not have focus. |
208 void CheckTaskbarOrViewHasFocus(); | 207 void CheckTaskbarOrViewHasFocus(); |
209 | 208 |
210 // Returns the underlying HWND for the AppList. | 209 // Returns the underlying HWND for the AppList. |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 return false; | 532 return false; |
534 | 533 |
535 RECT win_rect; | 534 RECT win_rect; |
536 if (!GetWindowRect(taskbar_hwnd, &win_rect)) | 535 if (!GetWindowRect(taskbar_hwnd, &win_rect)) |
537 return false; | 536 return false; |
538 | 537 |
539 *rect = gfx::Rect(win_rect); | 538 *rect = gfx::Rect(win_rect); |
540 return true; | 539 return true; |
541 } | 540 } |
542 | 541 |
543 // Used to position the view relative to a point, which requires |anchor| to be | 542 gfx::Point FindReferencePoint(const gfx::Display& display, |
544 // in the center of the desired view location. This helper function updates | 543 const gfx::Point& cursor) { |
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 | |
547 // represented in |direction|. | |
548 // 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 | |
550 // taskbar, one of the absolute values of |direction.x| and |direction.y| should | |
551 // be 1 and the other 0. | |
552 void FloatFromPoint(const gfx::Point& point, | |
553 const gfx::Size& offset, | |
554 const gfx::Point& direction, | |
555 gfx::Point* anchor) { | |
556 anchor->set_x(point.x() + direction.x() * offset.width()); | |
557 anchor->set_y(point.y() + direction.y() * offset.height()); | |
558 } | |
559 | |
560 void AppListController::SnapArrowLocationToTaskbarEdge( | |
561 const gfx::Display& display, | |
562 gfx::Point* anchor) { | |
563 const int kSnapDistance = 50; | 544 const int kSnapDistance = 50; |
564 const int kSnapOffset = 5; | |
565 | |
566 gfx::Rect taskbar_rect; | |
567 gfx::Size float_offset = current_view_->GetPreferredSize(); | |
568 float_offset.set_width(float_offset.width() / 2); | |
569 float_offset.set_height(float_offset.height() / 2); | |
570 float_offset.Enlarge(kSnapOffset, kSnapOffset); | |
571 | 545 |
572 // If we can't find the taskbar, snap to the bottom left. | 546 // 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 | 547 // 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 | 548 // taskbar, either the taskbar is hidden or on another monitor, so just snap |
575 // to the bottom left. | 549 // to the bottom left. |
| 550 gfx::Rect taskbar_rect; |
576 if (!GetTaskbarRect(&taskbar_rect) || | 551 if (!GetTaskbarRect(&taskbar_rect) || |
577 (display.work_area() == display.bounds() && | 552 (display.work_area() == display.bounds() && |
578 !display.work_area().Contains(taskbar_rect))) { | 553 !display.work_area().Contains(taskbar_rect))) { |
579 FloatFromPoint(display.work_area().bottom_left(), | 554 return display.work_area().bottom_left(); |
580 float_offset, | |
581 gfx::Point(1, -1), | |
582 anchor); | |
583 return; | |
584 } | 555 } |
585 | 556 |
586 const gfx::Rect& screen_rect = display.bounds(); | |
587 | |
588 // Snap to the taskbar edge. If the cursor is greater than kSnapDistance away, | 557 // 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). | 558 // also move to the left (for horizontal taskbars) or top (for vertical). |
590 | 559 const gfx::Rect& screen_rect = display.bounds(); |
591 // First handle taskbar on bottom. | 560 // First handle taskbar on bottom. |
592 if (taskbar_rect.width() == screen_rect.width()) { | 561 if (taskbar_rect.width() == screen_rect.width()) { |
593 if (taskbar_rect.bottom() == screen_rect.bottom()) { | 562 if (taskbar_rect.bottom() == screen_rect.bottom()) { |
594 if (taskbar_rect.y() - anchor->y() > kSnapDistance) { | 563 if (taskbar_rect.y() - cursor.y() > kSnapDistance) |
595 FloatFromPoint(gfx::Point(screen_rect.x(), taskbar_rect.y()), | 564 return gfx::Point(screen_rect.x(), taskbar_rect.y()); |
596 float_offset, | |
597 gfx::Point(1, -1), | |
598 anchor); | |
599 return; | |
600 } | |
601 | 565 |
602 FloatFromPoint(gfx::Point(anchor->x(), taskbar_rect.y()), | 566 return gfx::Point(cursor.x(), taskbar_rect.y()); |
603 float_offset, | |
604 gfx::Point(0, -1), | |
605 anchor); | |
606 return; | |
607 } | 567 } |
608 | 568 |
609 // Now try on the top. | 569 // Now try on the top. |
610 if (anchor->y() - taskbar_rect.bottom() > kSnapDistance) { | 570 if (cursor.y() - taskbar_rect.bottom() > kSnapDistance) |
611 FloatFromPoint(gfx::Point(screen_rect.x(), taskbar_rect.bottom()), | 571 return gfx::Point(screen_rect.x(), taskbar_rect.bottom()); |
612 float_offset, | |
613 gfx::Point(1, 1), | |
614 anchor); | |
615 return; | |
616 } | |
617 | 572 |
618 FloatFromPoint(gfx::Point(anchor->x(), taskbar_rect.bottom()), | 573 return gfx::Point(cursor.x(), taskbar_rect.bottom()); |
619 float_offset, | |
620 gfx::Point(0, 1), | |
621 anchor); | |
622 return; | |
623 } | 574 } |
624 | 575 |
625 // Now try the left. | 576 // Now try the left. |
626 if (taskbar_rect.x() == screen_rect.x()) { | 577 if (taskbar_rect.x() == screen_rect.x()) { |
627 if (anchor->x() - taskbar_rect.right() > kSnapDistance) { | 578 if (cursor.x() - taskbar_rect.right() > kSnapDistance) |
628 FloatFromPoint(gfx::Point(taskbar_rect.right(), screen_rect.y()), | 579 return gfx::Point(taskbar_rect.right(), screen_rect.y()); |
629 float_offset, | |
630 gfx::Point(1, 1), | |
631 anchor); | |
632 return; | |
633 } | |
634 | 580 |
635 FloatFromPoint(gfx::Point(taskbar_rect.right(), anchor->y()), | 581 return gfx::Point(taskbar_rect.right(), cursor.y()); |
636 float_offset, | |
637 gfx::Point(1, 0), | |
638 anchor); | |
639 return; | |
640 } | 582 } |
641 | 583 |
642 // Finally, try the right. | 584 // Finally, try the right. |
643 if (taskbar_rect.x() - anchor->x() > kSnapDistance) { | 585 if (taskbar_rect.x() - cursor.x() > kSnapDistance) |
644 FloatFromPoint(gfx::Point(taskbar_rect.x(), screen_rect.y()), | 586 return gfx::Point(taskbar_rect.x(), screen_rect.y()); |
645 float_offset, | |
646 gfx::Point(-1, 1), | |
647 anchor); | |
648 return; | |
649 } | |
650 | 587 |
651 FloatFromPoint(gfx::Point(taskbar_rect.x(), anchor->y()), | 588 return gfx::Point(taskbar_rect.x(), cursor.y()); |
652 float_offset, | 589 } |
653 gfx::Point(-1, 0), | 590 |
654 anchor); | 591 gfx::Point AppListController::FindAnchorPoint( |
| 592 const gfx::Display& display, |
| 593 const gfx::Point& cursor) { |
| 594 const int kSnapOffset = 3; |
| 595 |
| 596 gfx::Rect bounds_rect(display.work_area()); |
| 597 gfx::Size view_size(current_view_->GetPreferredSize()); |
| 598 bounds_rect.Inset(view_size.width() / 2 + kSnapOffset, |
| 599 view_size.height() / 2 + kSnapOffset); |
| 600 |
| 601 gfx::Point anchor = FindReferencePoint(display, cursor); |
| 602 anchor.ClampToMin(bounds_rect.origin()); |
| 603 anchor.ClampToMax(bounds_rect.bottom_right()); |
| 604 return anchor; |
655 } | 605 } |
656 | 606 |
657 void AppListController::UpdateArrowPositionAndAnchorPoint( | 607 void AppListController::UpdateArrowPositionAndAnchorPoint( |
658 const gfx::Point& cursor) { | 608 const gfx::Point& cursor) { |
659 gfx::Point anchor(cursor); | |
660 gfx::Screen* screen = | 609 gfx::Screen* screen = |
661 gfx::Screen::GetScreenFor(current_view_->GetWidget()->GetNativeView()); | 610 gfx::Screen::GetScreenFor(current_view_->GetWidget()->GetNativeView()); |
662 gfx::Display display = screen->GetDisplayNearestPoint(anchor); | 611 gfx::Display display = screen->GetDisplayNearestPoint(cursor); |
663 | |
664 SnapArrowLocationToTaskbarEdge(display, &anchor); | |
665 | 612 |
666 current_view_->SetBubbleArrowLocation(views::BubbleBorder::FLOAT); | 613 current_view_->SetBubbleArrowLocation(views::BubbleBorder::FLOAT); |
667 current_view_->SetAnchorPoint(anchor); | 614 current_view_->SetAnchorPoint(FindAnchorPoint(display, cursor)); |
668 } | 615 } |
669 | 616 |
670 string16 AppListController::GetAppListIconPath() { | 617 string16 AppListController::GetAppListIconPath() { |
671 base::FilePath icon_path; | 618 base::FilePath icon_path; |
672 if (!PathService::Get(base::FILE_EXE, &icon_path)) { | 619 if (!PathService::Get(base::FILE_EXE, &icon_path)) { |
673 NOTREACHED(); | 620 NOTREACHED(); |
674 return string16(); | 621 return string16(); |
675 } | 622 } |
676 | 623 |
677 std::stringstream ss; | 624 std::stringstream ss; |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
875 | 822 |
876 Profile* GetCurrentAppListProfile() { | 823 Profile* GetCurrentAppListProfile() { |
877 return GetCurrentAppListController()->profile(); | 824 return GetCurrentAppListController()->profile(); |
878 } | 825 } |
879 | 826 |
880 bool IsAppListVisible() { | 827 bool IsAppListVisible() { |
881 return GetCurrentAppListController()->IsAppListVisible(); | 828 return GetCurrentAppListController()->IsAppListVisible(); |
882 } | 829 } |
883 | 830 |
884 } // namespace chrome | 831 } // namespace chrome |
OLD | NEW |