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

Side by Side Diff: chrome/browser/ui/autofill/autofill_popup_controller_impl.cc

Issue 17743005: [Autofill] Ignore device scale factor when computing the Autofill popup position. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 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 "chrome/browser/ui/autofill/autofill_popup_controller_impl.h" 5 #include "chrome/browser/ui/autofill/autofill_popup_controller_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 gfx::Display AutofillPopupControllerImpl::GetDisplayNearestPoint( 600 gfx::Display AutofillPopupControllerImpl::GetDisplayNearestPoint(
601 const gfx::Point& point) const { 601 const gfx::Point& point) const {
602 return gfx::Screen::GetScreenFor(container_view())->GetDisplayNearestPoint( 602 return gfx::Screen::GetScreenFor(container_view())->GetDisplayNearestPoint(
603 point); 603 point);
604 } 604 }
605 605
606 std::pair<int, int> AutofillPopupControllerImpl::CalculatePopupXAndWidth( 606 std::pair<int, int> AutofillPopupControllerImpl::CalculatePopupXAndWidth(
607 const gfx::Display& left_display, 607 const gfx::Display& left_display,
608 const gfx::Display& right_display, 608 const gfx::Display& right_display,
609 int popup_required_width) const { 609 int popup_required_width) const {
610 int leftmost_display_x = left_display.bounds().x() * 610 int leftmost_display_x = left_display.bounds().x();
611 left_display.device_scale_factor(); 611 int rightmost_display_x =
612 int rightmost_display_x = right_display.GetSizeInPixel().width() + 612 right_display.GetSizeInPixel().width() + right_display.bounds().x();
613 right_display.bounds().x() * right_display.device_scale_factor();
614 613
615 // Calculate the start coordinates for the popup if it is growing right or 614 // Calculate the start coordinates for the popup if it is growing right or
616 // the end position if it is growing to the left, capped to screen space. 615 // the end position if it is growing to the left, capped to screen space.
617 int right_growth_start = std::max(leftmost_display_x, 616 int right_growth_start = std::max(leftmost_display_x,
618 std::min(rightmost_display_x, 617 std::min(rightmost_display_x,
619 RoundedElementBounds().x())); 618 RoundedElementBounds().x()));
620 int left_growth_end = std::max(leftmost_display_x, 619 int left_growth_end = std::max(leftmost_display_x,
621 std::min(rightmost_display_x, 620 std::min(rightmost_display_x,
622 RoundedElementBounds().right())); 621 RoundedElementBounds().right()));
623 622
624 int right_available = rightmost_display_x - right_growth_start; 623 int right_available = rightmost_display_x - right_growth_start;
625 int left_available = left_growth_end - leftmost_display_x; 624 int left_available = left_growth_end - leftmost_display_x;
626 625
627 int popup_width = std::min(popup_required_width, 626 int popup_width = std::min(popup_required_width,
628 std::max(right_available, left_available)); 627 std::max(right_available, left_available));
629 628
630 // If there is enough space for the popup on the right, show it there, 629 // If there is enough space for the popup on the right, show it there,
631 // otherwise choose the larger size. 630 // otherwise choose the larger size.
632 if (right_available >= popup_width || right_available >= left_available) 631 if (right_available >= popup_width || right_available >= left_available)
633 return std::make_pair(right_growth_start, popup_width); 632 return std::make_pair(right_growth_start, popup_width);
634 else 633 else
635 return std::make_pair(left_growth_end - popup_width, popup_width); 634 return std::make_pair(left_growth_end - popup_width, popup_width);
636 } 635 }
637 636
638 std::pair<int,int> AutofillPopupControllerImpl::CalculatePopupYAndHeight( 637 std::pair<int,int> AutofillPopupControllerImpl::CalculatePopupYAndHeight(
639 const gfx::Display& top_display, 638 const gfx::Display& top_display,
640 const gfx::Display& bottom_display, 639 const gfx::Display& bottom_display,
641 int popup_required_height) const { 640 int popup_required_height) const {
642 int topmost_display_y = top_display.bounds().y() * 641 int topmost_display_y = top_display.bounds().y();
643 top_display.device_scale_factor(); 642 int bottommost_display_y =
644 int bottommost_display_y = bottom_display.GetSizeInPixel().height() + 643 bottom_display.GetSizeInPixel().height() + bottom_display.bounds().y();
645 (bottom_display.bounds().y() *
646 bottom_display.device_scale_factor());
647 644
648 // Calculate the start coordinates for the popup if it is growing down or 645 // Calculate the start coordinates for the popup if it is growing down or
649 // the end position if it is growing up, capped to screen space. 646 // the end position if it is growing up, capped to screen space.
650 int top_growth_end = std::max(topmost_display_y, 647 int top_growth_end = std::max(topmost_display_y,
651 std::min(bottommost_display_y, 648 std::min(bottommost_display_y,
652 RoundedElementBounds().y())); 649 RoundedElementBounds().y()));
653 int bottom_growth_start = std::max(topmost_display_y, 650 int bottom_growth_start = std::max(topmost_display_y,
654 std::min(bottommost_display_y, RoundedElementBounds().bottom())); 651 std::min(bottommost_display_y, RoundedElementBounds().bottom()));
655 652
656 int top_available = bottom_growth_start - topmost_display_y; 653 int top_available = bottom_growth_start - topmost_display_y;
657 int bottom_available = bottommost_display_y - top_growth_end; 654 int bottom_available = bottommost_display_y - top_growth_end;
658 655
659 // TODO(csharp): Restrict the popup height to what is available. 656 // TODO(csharp): Restrict the popup height to what is available.
660 if (bottom_available >= popup_required_height || 657 if (bottom_available >= popup_required_height ||
661 bottom_available >= top_available) { 658 bottom_available >= top_available) {
662 // The popup can appear below the field. 659 // The popup can appear below the field.
663 return std::make_pair(bottom_growth_start, popup_required_height); 660 return std::make_pair(bottom_growth_start, popup_required_height);
664 } else { 661 } else {
665 // The popup must appear above the field. 662 // The popup must appear above the field.
666 return std::make_pair(top_growth_end - popup_required_height, 663 return std::make_pair(top_growth_end - popup_required_height,
667 popup_required_height); 664 popup_required_height);
668 } 665 }
669 } 666 }
670 667
671 } // namespace autofill 668 } // namespace autofill
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