|
@@ -6,19 +6,22 @@
|
|
|
#include <utility>
|
|
|
#include <vector>
|
|
|
|
|
|
-#if defined(ENABLE_OSR)
|
|
|
-#include "atom/browser/osr/osr_render_widget_host_view.h"
|
|
|
-#include "atom/browser/osr/osr_view_proxy.h"
|
|
|
-#endif
|
|
|
+#include "atom/browser/native_window_views.h"
|
|
|
#include "atom/browser/ui/autofill_popup.h"
|
|
|
#include "atom/common/api/api_messages.h"
|
|
|
#include "ui/display/display.h"
|
|
|
#include "ui/display/screen.h"
|
|
|
#include "ui/gfx/geometry/point.h"
|
|
|
#include "ui/gfx/geometry/rect.h"
|
|
|
+#include "ui/gfx/geometry/rect_conversions.h"
|
|
|
#include "ui/gfx/geometry/vector2d.h"
|
|
|
#include "ui/gfx/text_utils.h"
|
|
|
|
|
|
+#if defined(ENABLE_OSR)
|
|
|
+#include "atom/browser/osr/osr_render_widget_host_view.h"
|
|
|
+#include "atom/browser/osr/osr_view_proxy.h"
|
|
|
+#endif
|
|
|
+
|
|
|
namespace atom {
|
|
|
|
|
|
namespace {
|
|
@@ -95,20 +98,17 @@ std::pair<int, int> CalculatePopupYAndHeight(
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-display::Display GetDisplayNearestPoint(
|
|
|
- const gfx::Point& point,
|
|
|
- gfx::NativeView container_view) {
|
|
|
+display::Display GetDisplayNearestPoint(const gfx::Point& point) {
|
|
|
return display::Screen::GetScreen()->GetDisplayNearestPoint(point);
|
|
|
}
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
-AutofillPopup::AutofillPopup(gfx::NativeView container_view)
|
|
|
- : container_view_(container_view), view_(nullptr) {
|
|
|
+AutofillPopup::AutofillPopup() {
|
|
|
bold_font_list_ =
|
|
|
- gfx::FontList().DeriveWithWeight(gfx::Font::Weight::BOLD);
|
|
|
+ gfx::FontList().DeriveWithWeight(gfx::Font::Weight::BOLD);
|
|
|
smaller_font_list_ =
|
|
|
- gfx::FontList().DeriveWithSizeDelta(kSmallerFontSizeDelta);
|
|
|
+ gfx::FontList().DeriveWithSizeDelta(kSmallerFontSizeDelta);
|
|
|
}
|
|
|
|
|
|
AutofillPopup::~AutofillPopup() {
|
|
@@ -118,20 +118,17 @@ AutofillPopup::~AutofillPopup() {
|
|
|
void AutofillPopup::CreateView(
|
|
|
content::RenderFrameHost* frame_host,
|
|
|
bool offscreen,
|
|
|
- views::Widget* parent_widget,
|
|
|
+ views::View* parent,
|
|
|
const gfx::RectF& r) {
|
|
|
+ Hide();
|
|
|
+
|
|
|
frame_host_ = frame_host;
|
|
|
- gfx::Rect lb(std::floor(r.x()), std::floor(r.y() + r.height()),
|
|
|
- std::floor(r.width()), std::floor(r.height()));
|
|
|
- gfx::Point menu_position(lb.origin());
|
|
|
- popup_bounds_in_view_ = lb;
|
|
|
- views::View::ConvertPointToScreen(
|
|
|
- parent_widget->GetContentsView(), &menu_position);
|
|
|
- popup_bounds_ = gfx::Rect(menu_position, lb.size());
|
|
|
- element_bounds_ = popup_bounds_;
|
|
|
+ element_bounds_ = gfx::ToEnclosedRect(r);
|
|
|
|
|
|
- Hide();
|
|
|
- view_ = new AutofillPopupView(this, parent_widget);
|
|
|
+ parent_ = parent;
|
|
|
+ parent_->AddObserver(this);
|
|
|
+
|
|
|
+ view_ = new AutofillPopupView(this, parent->GetWidget());
|
|
|
view_->Show();
|
|
|
|
|
|
#if defined(ENABLE_OSR)
|
|
@@ -145,6 +142,10 @@ void AutofillPopup::CreateView(
|
|
|
}
|
|
|
|
|
|
void AutofillPopup::Hide() {
|
|
|
+ if (parent_) {
|
|
|
+ parent_->RemoveObserver(this);
|
|
|
+ parent_ = nullptr;
|
|
|
+ }
|
|
|
if (view_) {
|
|
|
view_->Hide();
|
|
|
view_ = nullptr;
|
|
@@ -152,28 +153,31 @@ void AutofillPopup::Hide() {
|
|
|
}
|
|
|
|
|
|
void AutofillPopup::SetItems(const std::vector<base::string16>& values,
|
|
|
- const std::vector<base::string16>& labels) {
|
|
|
+ const std::vector<base::string16>& labels) {
|
|
|
+ DCHECK(view_);
|
|
|
values_ = values;
|
|
|
labels_ = labels;
|
|
|
- if (view_) {
|
|
|
- view_->OnSuggestionsChanged();
|
|
|
- }
|
|
|
+ UpdatePopupBounds();
|
|
|
+ view_->OnSuggestionsChanged();
|
|
|
+ if (view_) // could be hidden after the change
|
|
|
+ view_->DoUpdateBoundsAndRedrawPopup();
|
|
|
}
|
|
|
|
|
|
void AutofillPopup::AcceptSuggestion(int index) {
|
|
|
frame_host_->Send(new AtomAutofillFrameMsg_AcceptSuggestion(
|
|
|
- frame_host_->GetRoutingID(), GetValueAt(index)));
|
|
|
+ frame_host_->GetRoutingID(), GetValueAt(index)));
|
|
|
}
|
|
|
|
|
|
-void AutofillPopup::UpdatePopupBounds(int height_compensation) {
|
|
|
+void AutofillPopup::UpdatePopupBounds() {
|
|
|
+ DCHECK(parent_);
|
|
|
+ gfx::Point origin(element_bounds_.origin());
|
|
|
+ views::View::ConvertPointToScreen(parent_, &origin);
|
|
|
+ gfx::Rect bounds(origin, element_bounds_.size());
|
|
|
+
|
|
|
int desired_width = GetDesiredPopupWidth();
|
|
|
int desired_height = GetDesiredPopupHeight();
|
|
|
bool is_rtl = false;
|
|
|
|
|
|
- gfx::Point origin(element_bounds_.origin().x(),
|
|
|
- element_bounds_.origin().y() - height_compensation);
|
|
|
- gfx::Rect bounds(origin, element_bounds_.size());
|
|
|
-
|
|
|
gfx::Point top_left_corner_of_popup =
|
|
|
origin + gfx::Vector2d(bounds.width() - desired_width, -desired_height);
|
|
|
|
|
@@ -184,9 +188,9 @@ void AutofillPopup::UpdatePopupBounds(int height_compensation) {
|
|
|
origin + gfx::Vector2d(desired_width, bounds.height() + desired_height);
|
|
|
|
|
|
display::Display top_left_display =
|
|
|
- GetDisplayNearestPoint(top_left_corner_of_popup, container_view_);
|
|
|
+ GetDisplayNearestPoint(top_left_corner_of_popup);
|
|
|
display::Display bottom_right_display =
|
|
|
- GetDisplayNearestPoint(bottom_right_corner_of_popup, container_view_);
|
|
|
+ GetDisplayNearestPoint(bottom_right_corner_of_popup);
|
|
|
|
|
|
std::pair<int, int> popup_x_and_width =
|
|
|
CalculatePopupXAndWidth(top_left_display, bottom_right_display,
|
|
@@ -201,8 +205,15 @@ void AutofillPopup::UpdatePopupBounds(int height_compensation) {
|
|
|
popup_bounds_in_view_ = gfx::Rect(
|
|
|
popup_bounds_in_view_.origin(),
|
|
|
gfx::Size(popup_x_and_width.second, popup_y_and_height.second));
|
|
|
- if (view_)
|
|
|
- view_->DoUpdateBoundsAndRedrawPopup();
|
|
|
+}
|
|
|
+
|
|
|
+void AutofillPopup::OnViewBoundsChanged(views::View* view) {
|
|
|
+ UpdatePopupBounds();
|
|
|
+ view_->DoUpdateBoundsAndRedrawPopup();
|
|
|
+}
|
|
|
+
|
|
|
+void AutofillPopup::OnViewIsDeleting(views::View* view) {
|
|
|
+ Hide();
|
|
|
}
|
|
|
|
|
|
int AutofillPopup::GetDesiredPopupHeight() {
|