fix datalist element popup position when menu is hidden
This commit is contained in:
parent
f8b3009ebf
commit
193beb57c9
3 changed files with 25 additions and 17 deletions
|
@ -1367,13 +1367,14 @@ void NativeWindowViews::ShowAutofillPopup(
|
||||||
bool isOffsceen = web_preferences->IsOffScreen(web_contents());
|
bool isOffsceen = web_preferences->IsOffScreen(web_contents());
|
||||||
bool isEmbedderOffscreen = web_preferences->IsGuest(web_contents()) &&
|
bool isEmbedderOffscreen = web_preferences->IsGuest(web_contents()) &&
|
||||||
web_preferences->IsOffScreen(web_preferences->Embedder(web_contents()));
|
web_preferences->IsOffScreen(web_preferences->Embedder(web_contents()));
|
||||||
|
|
||||||
autofill_popup_->CreateView(
|
autofill_popup_->CreateView(
|
||||||
frame_host,
|
frame_host,
|
||||||
isOffsceen || isEmbedderOffscreen,
|
isOffsceen || isEmbedderOffscreen,
|
||||||
widget(),
|
widget(),
|
||||||
bounds);
|
bounds);
|
||||||
autofill_popup_->SetItems(values, labels);
|
autofill_popup_->SetItems(values, labels);
|
||||||
|
autofill_popup_->UpdatePopupBounds(menu_bar_visible_ ? 0 : kMenuBarHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeWindowViews::HideAutofillPopup(
|
void NativeWindowViews::HideAutofillPopup(
|
||||||
|
@ -1395,6 +1396,9 @@ void NativeWindowViews::Layout() {
|
||||||
gfx::Rect(0, menu_bar_bounds.height(), size.width(),
|
gfx::Rect(0, menu_bar_bounds.height(), size.width(),
|
||||||
size.height() - menu_bar_bounds.height()));
|
size.height() - menu_bar_bounds.height()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (autofill_popup_.get())
|
||||||
|
autofill_popup_->UpdatePopupBounds(menu_bar_visible_ ? 0 : kMenuBarHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
gfx::Size NativeWindowViews::GetMinimumSize() const {
|
gfx::Size NativeWindowViews::GetMinimumSize() const {
|
||||||
|
|
|
@ -155,7 +155,6 @@ void AutofillPopup::SetItems(const std::vector<base::string16>& values,
|
||||||
const std::vector<base::string16>& labels) {
|
const std::vector<base::string16>& labels) {
|
||||||
values_ = values;
|
values_ = values;
|
||||||
labels_ = labels;
|
labels_ = labels;
|
||||||
UpdatePopupBounds();
|
|
||||||
if (view_) {
|
if (view_) {
|
||||||
view_->OnSuggestionsChanged();
|
view_->OnSuggestionsChanged();
|
||||||
}
|
}
|
||||||
|
@ -166,37 +165,41 @@ void AutofillPopup::AcceptSuggestion(int index) {
|
||||||
frame_host_->GetRoutingID(), GetValueAt(index)));
|
frame_host_->GetRoutingID(), GetValueAt(index)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void AutofillPopup::UpdatePopupBounds() {
|
void AutofillPopup::UpdatePopupBounds(int height_compensation) {
|
||||||
int desired_width = GetDesiredPopupWidth();
|
int desired_width = GetDesiredPopupWidth();
|
||||||
int desired_height = GetDesiredPopupHeight();
|
int desired_height = GetDesiredPopupHeight();
|
||||||
bool is_rtl = false;
|
bool is_rtl = false;
|
||||||
|
|
||||||
gfx::Point top_left_corner_of_popup =
|
gfx::Point origin(element_bounds_.origin().x(),
|
||||||
element_bounds_.origin() +
|
element_bounds_.origin().y() - height_compensation);
|
||||||
gfx::Vector2d(element_bounds_.width() - desired_width, -desired_height);
|
gfx::Rect bounds(origin, element_bounds_.size());
|
||||||
|
|
||||||
|
gfx::Point top_left_corner_of_popup = origin +
|
||||||
|
gfx::Vector2d(bounds.width() - desired_width, -desired_height);
|
||||||
|
|
||||||
// This is the bottom right point of the popup if the popup is below the
|
// This is the bottom right point of the popup if the popup is below the
|
||||||
// element and grows to the right (since the is the lowest and furthest right
|
// element and grows to the right (since the is the lowest and furthest right
|
||||||
// the popup could go).
|
// the popup could go).
|
||||||
gfx::Point bottom_right_corner_of_popup =
|
gfx::Point bottom_right_corner_of_popup = origin +
|
||||||
element_bounds_.origin() +
|
gfx::Vector2d(desired_width, bounds.height() + desired_height);
|
||||||
gfx::Vector2d(desired_width, element_bounds_.height() + desired_height);
|
|
||||||
|
|
||||||
display::Display top_left_display =
|
display::Display top_left_display =
|
||||||
GetDisplayNearestPoint(top_left_corner_of_popup, container_view_);
|
GetDisplayNearestPoint(top_left_corner_of_popup, container_view_);
|
||||||
display::Display bottom_right_display =
|
display::Display bottom_right_display =
|
||||||
GetDisplayNearestPoint(bottom_right_corner_of_popup, container_view_);
|
GetDisplayNearestPoint(bottom_right_corner_of_popup, container_view_);
|
||||||
|
|
||||||
std::pair<int, int> popup_x_and_width =
|
std::pair<int, int> popup_x_and_width =
|
||||||
CalculatePopupXAndWidth(top_left_display, bottom_right_display,
|
CalculatePopupXAndWidth(top_left_display, bottom_right_display,
|
||||||
desired_width, element_bounds_, is_rtl);
|
desired_width, bounds, is_rtl);
|
||||||
std::pair<int, int> popup_y_and_height = CalculatePopupYAndHeight(
|
std::pair<int, int> popup_y_and_height = CalculatePopupYAndHeight(
|
||||||
top_left_display, bottom_right_display, desired_height, element_bounds_);
|
top_left_display, bottom_right_display, desired_height, bounds);
|
||||||
|
|
||||||
popup_bounds_ = gfx::Rect(popup_x_and_width.first, popup_y_and_height.first,
|
popup_bounds_ = gfx::Rect(popup_x_and_width.first, popup_y_and_height.first,
|
||||||
popup_x_and_width.second, popup_y_and_height.second);
|
popup_x_and_width.second, popup_y_and_height.second);
|
||||||
popup_bounds_in_view_ = gfx::Rect(popup_bounds_in_view_.origin(),
|
popup_bounds_in_view_ = gfx::Rect(popup_bounds_in_view_.origin(),
|
||||||
gfx::Size(popup_x_and_width.second, popup_y_and_height.second));
|
gfx::Size(popup_x_and_width.second, popup_y_and_height.second));
|
||||||
|
if (view_)
|
||||||
|
view_->DoUpdateBoundsAndRedrawPopup();
|
||||||
}
|
}
|
||||||
|
|
||||||
int AutofillPopup::GetDesiredPopupHeight() {
|
int AutofillPopup::GetDesiredPopupHeight() {
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#include "ui/gfx/font_list.h"
|
#include "ui/gfx/font_list.h"
|
||||||
#include "ui/native_theme/native_theme.h"
|
#include "ui/native_theme/native_theme.h"
|
||||||
#include "ui/views/widget/widget.h"
|
#include "ui/views/widget/widget.h"
|
||||||
|
#include "ui/views/view.h"
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
|
@ -28,13 +29,13 @@ class AutofillPopup {
|
||||||
|
|
||||||
void SetItems(const std::vector<base::string16>& values,
|
void SetItems(const std::vector<base::string16>& values,
|
||||||
const std::vector<base::string16>& labels);
|
const std::vector<base::string16>& labels);
|
||||||
|
void UpdatePopupBounds(int height_compensation);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class AutofillPopupView;
|
friend class AutofillPopupView;
|
||||||
|
|
||||||
void AcceptSuggestion(int index);
|
void AcceptSuggestion(int index);
|
||||||
|
|
||||||
void UpdatePopupBounds();
|
|
||||||
int GetDesiredPopupHeight();
|
int GetDesiredPopupHeight();
|
||||||
int GetDesiredPopupWidth();
|
int GetDesiredPopupWidth();
|
||||||
gfx::Rect GetRowBounds(int i);
|
gfx::Rect GetRowBounds(int i);
|
||||||
|
|
Loading…
Reference in a new issue