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

Side by Side Diff: chrome/browser/ui/views/app_list/app_list_controller_win.cc

Issue 12334115: [win] Ensure the app launcher always comes up on screen. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More neater Created 7 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | 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 <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 522 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 return false; 533 return false;
534 534
535 RECT win_rect; 535 RECT win_rect;
536 if (!GetWindowRect(taskbar_hwnd, &win_rect)) 536 if (!GetWindowRect(taskbar_hwnd, &win_rect))
537 return false; 537 return false;
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 gfx::Point FindReferencePoint(const gfx::Display& display,
544 // in the center of the desired view location. This helper function updates 544 gfx::Point* anchor) {
tapted 2013/02/27 11:58:48 i think |anchor| can be const reference now
benwells 2013/02/27 22:35:42 Yeah, and in the next function. Done.
545 // |anchor| thus, using the location of the point in |point|, the distance 545 const int kSnapDistance = 50;
546 // to move the view from |point| in |offset|, and the direction to move 546
547 // represented in |direction|. 547 // If we can't find the taskbar, snap to the bottom left.
548 // To position relative to a screen corner, the absolute values of |direction|.x 548 // If the display size is the same as the work area, and does not contain the
549 // and |direction.y| should both be 1. To position relative to some point on the 549 // taskbar, either the taskbar is hidden or on another monitor, so just snap
550 // taskbar, one of the absolute values of |direction.x| and |direction.y| should 550 // to the bottom left.
551 // be 1 and the other 0. 551 gfx::Rect taskbar_rect;
552 void FloatFromPoint(const gfx::Point& point, 552 if (!GetTaskbarRect(&taskbar_rect) ||
553 const gfx::Size& offset, 553 (display.work_area() == display.bounds() &&
554 const gfx::Point& direction, 554 !display.work_area().Contains(taskbar_rect))) {
555 gfx::Point* anchor) { 555 return display.work_area().bottom_left();
556 anchor->set_x(point.x() + direction.x() * offset.width()); 556 }
557 anchor->set_y(point.y() + direction.y() * offset.height()); 557
558 // Snap to the taskbar edge. If the cursor is greater than kSnapDistance away,
559 // also move to the left (for horizontal taskbars) or top (for vertical).
560 const gfx::Rect& screen_rect = display.bounds();
561 // First handle taskbar on bottom.
562 if (taskbar_rect.width() == screen_rect.width()) {
563 if (taskbar_rect.bottom() == screen_rect.bottom()) {
564 if (taskbar_rect.y() - anchor->y() > kSnapDistance)
565 return gfx::Point(screen_rect.x(), taskbar_rect.y());
566
567 return gfx::Point(anchor->x(), taskbar_rect.y());
568 }
569
570 // Now try on the top.
571 if (anchor->y() - taskbar_rect.bottom() > kSnapDistance)
572 return gfx::Point(screen_rect.x(), taskbar_rect.bottom());
573
574 return gfx::Point(anchor->x(), taskbar_rect.bottom());
575 }
576
577 // Now try the left.
578 if (taskbar_rect.x() == screen_rect.x()) {
579 if (anchor->x() - taskbar_rect.right() > kSnapDistance)
580 return gfx::Point(taskbar_rect.right(), screen_rect.y());
581
582 return gfx::Point(taskbar_rect.right(), anchor->y());
583 }
584
585 // Finally, try the right.
586 if (taskbar_rect.x() - anchor->x() > kSnapDistance)
587 return gfx::Point(taskbar_rect.x(), screen_rect.y());
588
589 return gfx::Point(taskbar_rect.x(), anchor->y());
558 } 590 }
559 591
560 void AppListController::SnapArrowLocationToTaskbarEdge( 592 void AppListController::SnapArrowLocationToTaskbarEdge(
561 const gfx::Display& display, 593 const gfx::Display& display,
562 gfx::Point* anchor) { 594 gfx::Point* anchor) {
563 const int kSnapDistance = 50; 595 const int kSnapOffset = 3;
564 const int kSnapOffset = 5;
565 596
566 gfx::Rect taskbar_rect; 597 gfx::Rect bounds_rect(display.work_area());
567 gfx::Size float_offset = current_view_->GetPreferredSize(); 598 gfx::Size view_size(current_view_->GetPreferredSize());
568 float_offset.set_width(float_offset.width() / 2); 599 bounds_rect.Inset(view_size.width() / 2 + kSnapOffset,
569 float_offset.set_height(float_offset.height() / 2); 600 view_size.height() / 2 + kSnapOffset);
570 float_offset.Enlarge(kSnapOffset, kSnapOffset);
571 601
572 // If we can't find the taskbar, snap to the bottom left. 602 gfx::Point ref_point(FindReferencePoint(display, anchor));
573 // If the display size is the same as the work area, and does not contain the 603 anchor->SetPoint(ref_point.x(), ref_point.y());
tapted 2013/02/27 11:58:48 I don't... think default assignment operator has b
benwells 2013/02/27 22:35:42 Yep, good one.
574 // taskbar, either the taskbar is hidden or on another monitor, so just snap 604 anchor->ClampToMin(bounds_rect.origin());
tapted 2013/02/27 11:58:48 ah, origin - of course ;). (Cocoa has had me think
575 // to the bottom left. 605 anchor->ClampToMax(bounds_rect.bottom_right());
576 if (!GetTaskbarRect(&taskbar_rect) ||
577 (display.work_area() == display.bounds() &&
578 !display.work_area().Contains(taskbar_rect))) {
579 FloatFromPoint(display.work_area().bottom_left(),
580 float_offset,
581 gfx::Point(1, -1),
582 anchor);
583 return;
584 }
585
586 const gfx::Rect& screen_rect = display.bounds();
587
588 // 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).
590
591 // First handle taskbar on bottom.
592 if (taskbar_rect.width() == screen_rect.width()) {
593 if (taskbar_rect.bottom() == screen_rect.bottom()) {
594 if (taskbar_rect.y() - anchor->y() > kSnapDistance) {
595 FloatFromPoint(gfx::Point(screen_rect.x(), taskbar_rect.y()),
596 float_offset,
597 gfx::Point(1, -1),
598 anchor);
599 return;
600 }
601
602 FloatFromPoint(gfx::Point(anchor->x(), taskbar_rect.y()),
603 float_offset,
604 gfx::Point(0, -1),
605 anchor);
606 return;
607 }
608
609 // Now try on the top.
610 if (anchor->y() - taskbar_rect.bottom() > kSnapDistance) {
611 FloatFromPoint(gfx::Point(screen_rect.x(), taskbar_rect.bottom()),
612 float_offset,
613 gfx::Point(1, 1),
614 anchor);
615 return;
616 }
617
618 FloatFromPoint(gfx::Point(anchor->x(), taskbar_rect.bottom()),
619 float_offset,
620 gfx::Point(0, 1),
621 anchor);
622 return;
623 }
624
625 // Now try the left.
626 if (taskbar_rect.x() == screen_rect.x()) {
627 if (anchor->x() - taskbar_rect.right() > kSnapDistance) {
628 FloatFromPoint(gfx::Point(taskbar_rect.right(), screen_rect.y()),
629 float_offset,
630 gfx::Point(1, 1),
631 anchor);
632 return;
633 }
634
635 FloatFromPoint(gfx::Point(taskbar_rect.right(), anchor->y()),
636 float_offset,
637 gfx::Point(1, 0),
638 anchor);
639 return;
640 }
641
642 // Finally, try the right.
643 if (taskbar_rect.x() - anchor->x() > kSnapDistance) {
644 FloatFromPoint(gfx::Point(taskbar_rect.x(), screen_rect.y()),
645 float_offset,
646 gfx::Point(-1, 1),
647 anchor);
648 return;
649 }
650
651 FloatFromPoint(gfx::Point(taskbar_rect.x(), anchor->y()),
652 float_offset,
653 gfx::Point(-1, 0),
654 anchor);
655 } 606 }
656 607
657 void AppListController::UpdateArrowPositionAndAnchorPoint( 608 void AppListController::UpdateArrowPositionAndAnchorPoint(
658 const gfx::Point& cursor) { 609 const gfx::Point& cursor) {
659 gfx::Point anchor(cursor); 610 gfx::Point anchor(cursor);
660 gfx::Screen* screen = 611 gfx::Screen* screen =
661 gfx::Screen::GetScreenFor(current_view_->GetWidget()->GetNativeView()); 612 gfx::Screen::GetScreenFor(current_view_->GetWidget()->GetNativeView());
662 gfx::Display display = screen->GetDisplayNearestPoint(anchor); 613 gfx::Display display = screen->GetDisplayNearestPoint(anchor);
663 614
664 SnapArrowLocationToTaskbarEdge(display, &anchor); 615 SnapArrowLocationToTaskbarEdge(display, &anchor);
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
875 826
876 Profile* GetCurrentAppListProfile() { 827 Profile* GetCurrentAppListProfile() {
877 return GetCurrentAppListController()->profile(); 828 return GetCurrentAppListController()->profile();
878 } 829 }
879 830
880 bool IsAppListVisible() { 831 bool IsAppListVisible() {
881 return GetCurrentAppListController()->IsAppListVisible(); 832 return GetCurrentAppListController()->IsAppListVisible();
882 } 833 }
883 834
884 } // namespace chrome 835 } // namespace chrome
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698