🎨 lint fix
This commit is contained in:
parent
f360104bee
commit
4949531f57
8 changed files with 88 additions and 76 deletions
|
@ -749,7 +749,7 @@ void WebContents::RenderFrameCreated(content::RenderFrameHost* host) {
|
|||
host->GetRoutingID(), routing_id()));
|
||||
}
|
||||
|
||||
void WebContents::RenderFrameHostChanged(content::RenderFrameHost* old_host,
|
||||
void WebContents::RenderFrameHostChanged(content::RenderFrameHost* old_host,
|
||||
content::RenderFrameHost* new_host) {
|
||||
Send(new AtomAutofillViewHostMsg_RoutingId(
|
||||
new_host->GetRoutingID(), routing_id()));
|
||||
|
@ -1628,14 +1628,14 @@ void WebContents::OnCursorChange(const content::WebCursor& cursor) {
|
|||
void WebContents::OnShowAutofillPopup(
|
||||
int routing_id,
|
||||
const gfx::RectF& bounds,
|
||||
const std::vector<base::string16>& values,
|
||||
const std::vector<base::string16>& labels) {
|
||||
const std::vector<base::string16>& values,
|
||||
const std::vector<base::string16>& labels) {
|
||||
auto relay = reinterpret_cast<NativeWindowViews*>(
|
||||
NativeWindow::FromWebContents(web_contents()));
|
||||
autofill_popup_->CreateView(
|
||||
routing_id,
|
||||
web_contents(),
|
||||
relay->widget(),
|
||||
relay->widget(),
|
||||
bounds);
|
||||
autofill_popup_->SetItems(values, labels);
|
||||
}
|
||||
|
|
|
@ -309,7 +309,7 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
|||
void BeforeUnloadFired(const base::TimeTicks& proceed_time) override;
|
||||
void RenderViewCreated(content::RenderViewHost*) override;
|
||||
void RenderFrameCreated(content::RenderFrameHost*) override;
|
||||
void RenderFrameHostChanged(content::RenderFrameHost*,
|
||||
void RenderFrameHostChanged(content::RenderFrameHost*,
|
||||
content::RenderFrameHost*) override;
|
||||
void RenderViewDeleted(content::RenderViewHost*) override;
|
||||
void RenderProcessGone(base::TerminationStatus status) override;
|
||||
|
@ -377,10 +377,10 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
|||
|
||||
// Called when we receive a CursorChange message from chromium.
|
||||
void OnCursorChange(const content::WebCursor& cursor);
|
||||
|
||||
|
||||
void OnShowAutofillPopup(int routing_id,
|
||||
const gfx::RectF& bounds,
|
||||
const std::vector<base::string16>& values,
|
||||
const std::vector<base::string16>& values,
|
||||
const std::vector<base::string16>& labels);
|
||||
void OnHideAutofillPopup();
|
||||
|
||||
|
|
|
@ -2,14 +2,18 @@
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#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/text_utils.h"
|
||||
#include "ui/gfx/geometry/point.h"
|
||||
#include "ui/gfx/geometry/rect.h"
|
||||
#include "ui/gfx/geometry/vector2d.h"
|
||||
#include "ui/gfx/text_utils.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
|
@ -97,9 +101,9 @@ display::Display GetDisplayNearestPoint(
|
|||
|
||||
AutofillPopup::AutofillPopup(gfx::NativeView container_view)
|
||||
: container_view_(container_view) {
|
||||
bold_font_list_ =
|
||||
bold_font_list_ =
|
||||
gfx::FontList().DeriveWithWeight(gfx::Font::Weight::BOLD);
|
||||
smaller_font_list_ =
|
||||
smaller_font_list_ =
|
||||
gfx::FontList().DeriveWithSizeDelta(kSmallerFontSizeDelta);
|
||||
}
|
||||
|
||||
|
@ -110,19 +114,20 @@ AutofillPopup::~AutofillPopup() {
|
|||
void AutofillPopup::CreateView(
|
||||
int routing_id,
|
||||
content::WebContents* web_contents,
|
||||
views::Widget* parent_widget,
|
||||
views::Widget* parent_widget,
|
||||
const gfx::RectF& r) {
|
||||
web_contents_ = web_contents;
|
||||
gfx::Rect lb(std::floor(r.x()), std::floor(r.y() + r.height()),
|
||||
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());
|
||||
views::View::ConvertPointToScreen(parent_widget->GetContentsView(), &menu_position);
|
||||
views::View::ConvertPointToScreen(
|
||||
parent_widget->GetContentsView(), &menu_position);
|
||||
popup_bounds_ = gfx::Rect(menu_position, lb.size());
|
||||
element_bounds_ = popup_bounds_;
|
||||
|
||||
|
||||
view_.reset(new AutofillPopupView(this, parent_widget));
|
||||
view_->Show();
|
||||
|
||||
|
||||
frame_routing_id_ = routing_id;
|
||||
}
|
||||
|
||||
|
@ -152,7 +157,7 @@ void AutofillPopup::UpdatePopupBounds() {
|
|||
int desired_width = GetDesiredPopupWidth();
|
||||
int desired_height = GetDesiredPopupHeight();
|
||||
bool is_rtl = false;
|
||||
|
||||
|
||||
gfx::Point top_left_corner_of_popup =
|
||||
element_bounds_.origin() +
|
||||
gfx::Vector2d(element_bounds_.width() - desired_width, -desired_height);
|
||||
|
@ -187,10 +192,10 @@ int AutofillPopup::GetDesiredPopupWidth() {
|
|||
int popup_width = element_bounds_.width();
|
||||
|
||||
for (int i = 0; i < values_.size(); ++i) {
|
||||
int row_size = kEndPadding + 2 * kPopupBorderThickness +
|
||||
gfx::GetStringWidth(GetValueAt(i), GetValueFontListForRow(i)) +
|
||||
int row_size = kEndPadding + 2 * kPopupBorderThickness +
|
||||
gfx::GetStringWidth(GetValueAt(i), GetValueFontListForRow(i)) +
|
||||
gfx::GetStringWidth(GetLabelAt(i), GetLabelFontListForRow(i));
|
||||
if (GetLabelAt(i).length() > 0)
|
||||
if (GetLabelAt(i).length() > 0)
|
||||
row_size += kNamePadding + kEndPadding;
|
||||
|
||||
popup_width = std::max(popup_width, row_size);
|
||||
|
@ -243,8 +248,8 @@ int AutofillPopup::LineFromY(int y) const {
|
|||
if (y <= current_height)
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
return values_.size() - 1;
|
||||
}
|
||||
|
||||
} // namespace atom
|
||||
} // namespace atom
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
#ifndef ATOM_BROWSER_UI_AUTOFILL_POPUP_H_
|
||||
#define ATOM_BROWSER_UI_AUTOFILL_POPUP_H_
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "atom/browser/ui/views/autofill_popup_view.h"
|
||||
#include "content/public/browser/web_contents.h"
|
||||
#include "ui/gfx/font_list.h"
|
||||
|
@ -14,23 +16,24 @@
|
|||
namespace atom {
|
||||
|
||||
class AutofillPopupView;
|
||||
|
||||
|
||||
class AutofillPopup {
|
||||
public:
|
||||
AutofillPopup(gfx::NativeView);
|
||||
explicit AutofillPopup(gfx::NativeView);
|
||||
~AutofillPopup();
|
||||
|
||||
void CreateView(int routing_id, content::WebContents* web_contents,
|
||||
views::Widget* widget, const gfx::RectF& bounds);
|
||||
void Hide();
|
||||
|
||||
|
||||
void SetItems(const std::vector<base::string16>& values,
|
||||
const std::vector<base::string16>& labels);
|
||||
|
||||
private:
|
||||
friend class AutofillPopupView;
|
||||
|
||||
|
||||
void AcceptSuggestion(int index);
|
||||
|
||||
|
||||
void UpdatePopupBounds();
|
||||
int GetDesiredPopupHeight();
|
||||
int GetDesiredPopupWidth();
|
||||
|
@ -38,36 +41,36 @@ class AutofillPopup {
|
|||
const gfx::FontList& GetValueFontListForRow(int index) const;
|
||||
const gfx::FontList& GetLabelFontListForRow(int index) const;
|
||||
ui::NativeTheme::ColorId GetBackgroundColorIDForRow(int index) const;
|
||||
|
||||
|
||||
int GetLineCount();
|
||||
base::string16 GetValueAt(int i);
|
||||
base::string16 GetLabelAt(int i);
|
||||
int LineFromY(int y) const;
|
||||
|
||||
|
||||
// The native view that contains this
|
||||
gfx::NativeView container_view_;
|
||||
|
||||
|
||||
int selected_index_;
|
||||
|
||||
|
||||
// Popup location
|
||||
gfx::Rect popup_bounds_;
|
||||
|
||||
|
||||
// Bounds of the autofilled element
|
||||
gfx::Rect element_bounds_;
|
||||
|
||||
|
||||
// Datalist suggestions
|
||||
std::vector<base::string16> values_;
|
||||
std::vector<base::string16> labels_;
|
||||
|
||||
|
||||
// Font lists for the suggestions
|
||||
gfx::FontList smaller_font_list_;
|
||||
gfx::FontList bold_font_list_;
|
||||
|
||||
// For sending the accepted suggestion to the render frame that
|
||||
|
||||
// For sending the accepted suggestion to the render frame that
|
||||
// asked to open the popup
|
||||
int frame_routing_id_;
|
||||
content::WebContents* web_contents_;
|
||||
|
||||
|
||||
// The popup view
|
||||
std::unique_ptr<AutofillPopupView> view_;
|
||||
|
||||
|
@ -76,4 +79,4 @@ class AutofillPopup {
|
|||
|
||||
} // namespace atom
|
||||
|
||||
#endif // ATOM_BROWSER_UI_AUTOFILL_POPUP_H_
|
||||
#endif // ATOM_BROWSER_UI_AUTOFILL_POPUP_H_
|
||||
|
|
|
@ -80,7 +80,7 @@ void AutofillPopupView::Show() {
|
|||
|
||||
if (initialize_widget)
|
||||
views::WidgetFocusManager::GetInstance()->AddFocusChangeListener(this);
|
||||
|
||||
|
||||
keypress_callback_ = base::Bind(&AutofillPopupView::HandleKeyPressEvent,
|
||||
base::Unretained(this));
|
||||
auto host = popup_->web_contents_->GetRenderViewHost()->GetWidget();
|
||||
|
@ -129,13 +129,13 @@ void AutofillPopupView::DrawAutofillEntry(gfx::Canvas* canvas,
|
|||
entry_rect,
|
||||
GetNativeTheme()->GetSystemColor(
|
||||
popup_->GetBackgroundColorIDForRow(index)));
|
||||
|
||||
|
||||
const bool is_rtl = false;
|
||||
const int text_align =
|
||||
is_rtl ? gfx::Canvas::TEXT_ALIGN_RIGHT : gfx::Canvas::TEXT_ALIGN_LEFT;
|
||||
gfx::Rect value_rect = entry_rect;
|
||||
value_rect.Inset(kEndPadding, 0);
|
||||
|
||||
|
||||
int x_align_left = value_rect.x();
|
||||
const int value_width = gfx::GetStringWidth(
|
||||
popup_->GetValueAt(index),
|
||||
|
@ -143,7 +143,7 @@ void AutofillPopupView::DrawAutofillEntry(gfx::Canvas* canvas,
|
|||
int value_x_align_left = x_align_left;
|
||||
value_x_align_left =
|
||||
is_rtl ? value_rect.right() - value_width : value_rect.x();
|
||||
|
||||
|
||||
canvas->DrawStringRectWithFlags(
|
||||
popup_->GetValueAt(index),
|
||||
popup_->GetValueFontListForRow(index),
|
||||
|
@ -159,7 +159,7 @@ void AutofillPopupView::DrawAutofillEntry(gfx::Canvas* canvas,
|
|||
popup_->GetLabelAt(index),
|
||||
popup_->GetLabelFontListForRow(index));
|
||||
int label_x_align_left = x_align_left;
|
||||
label_x_align_left =
|
||||
label_x_align_left =
|
||||
is_rtl ? value_rect.x() : value_rect.right() - label_width;
|
||||
|
||||
canvas->DrawStringRectWithFlags(
|
||||
|
@ -191,15 +191,15 @@ void AutofillPopupView::DoUpdateBoundsAndRedrawPopup() {
|
|||
void AutofillPopupView::OnPaint(gfx::Canvas* canvas) {
|
||||
if (!popup_)
|
||||
return;
|
||||
|
||||
|
||||
canvas->DrawColor(GetNativeTheme()->GetSystemColor(
|
||||
ui::NativeTheme::kColorId_ResultsTableNormalBackground));
|
||||
OnPaintBorder(canvas);
|
||||
|
||||
|
||||
DCHECK_EQ(popup_->GetLineCount(), child_count());
|
||||
for (int i = 0; i < popup_->GetLineCount(); ++i) {
|
||||
gfx::Rect line_rect = popup_->GetRowBounds(i);
|
||||
|
||||
|
||||
DrawAutofillEntry(canvas, i, line_rect);
|
||||
}
|
||||
}
|
||||
|
@ -411,4 +411,4 @@ void AutofillPopupView::RemoveObserver() {
|
|||
views::WidgetFocusManager::GetInstance()->RemoveFocusChangeListener(this);
|
||||
}
|
||||
|
||||
} // namespace atom
|
||||
} // namespace atom
|
||||
|
|
|
@ -57,12 +57,12 @@ class AutofillPopupView : public views::WidgetDelegateView,
|
|||
explicit AutofillPopupView(AutofillPopup* popup,
|
||||
views::Widget* parent_widget);
|
||||
~AutofillPopupView() override;
|
||||
|
||||
|
||||
void Show();
|
||||
void Hide();
|
||||
|
||||
|
||||
void OnSuggestionsChanged();
|
||||
|
||||
|
||||
int GetSelectedLine() { return selected_line_.value_or(-1); }
|
||||
|
||||
void WriteDragDataForView(
|
||||
|
@ -71,8 +71,8 @@ class AutofillPopupView : public views::WidgetDelegateView,
|
|||
return ui::DragDropTypes::DRAG_NONE;
|
||||
}
|
||||
bool CanStartDragForView(
|
||||
views::View*, const gfx::Point&, const gfx::Point&) override {
|
||||
return false;
|
||||
views::View*, const gfx::Point&, const gfx::Point&) override {
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -88,9 +88,9 @@ class AutofillPopupView : public views::WidgetDelegateView,
|
|||
// child views are used for accessibility events only. We need child views to
|
||||
// populate the correct |AXNodeData| when user selects a suggestion.
|
||||
void CreateChildViews();
|
||||
|
||||
|
||||
void DoUpdateBoundsAndRedrawPopup();
|
||||
|
||||
|
||||
// views::Views implementation.
|
||||
void OnPaint(gfx::Canvas* canvas) override;
|
||||
void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
|
||||
|
@ -103,7 +103,7 @@ class AutofillPopupView : public views::WidgetDelegateView,
|
|||
void OnGestureEvent(ui::GestureEvent* event) override;
|
||||
bool AcceleratorPressed(const ui::Accelerator& accelerator) override;
|
||||
bool HandleKeyPressEvent(const content::NativeWebKeyboardEvent& event);
|
||||
|
||||
|
||||
// views::WidgetFocusChangeListener implementation.
|
||||
void OnNativeFocusChanged(gfx::NativeView focused_now) override;
|
||||
|
||||
|
@ -131,10 +131,10 @@ class AutofillPopupView : public views::WidgetDelegateView,
|
|||
|
||||
// The time when the popup was shown.
|
||||
base::Time show_time_;
|
||||
|
||||
|
||||
// The index of the currently selected line
|
||||
base::Optional<int> selected_line_;
|
||||
|
||||
|
||||
// The registered keypress callback, responsible for switching lines on
|
||||
// key presses
|
||||
content::RenderWidgetHost::KeyPressEventCallback keypress_callback_;
|
||||
|
@ -144,4 +144,4 @@ class AutofillPopupView : public views::WidgetDelegateView,
|
|||
|
||||
} // namespace atom
|
||||
|
||||
#endif // ATOM_BROWSER_UI_VIEWS_AUTOFILL_POPUP_VIEW_H_
|
||||
#endif // ATOM_BROWSER_UI_VIEWS_AUTOFILL_POPUP_VIEW_H_
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
#include "atom/renderer/atom_autofill_agent.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "atom/common/api/api_messages.h"
|
||||
#include "content/public/renderer/render_frame.h"
|
||||
#include "content/public/renderer/render_view.h"
|
||||
|
@ -17,11 +19,11 @@
|
|||
#include "ui/gfx/geometry/rect_f.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
|
||||
namespace {
|
||||
const size_t kMaxDataLength = 1024;
|
||||
const size_t kMaxListSize = 512;
|
||||
|
||||
|
||||
void GetDataListSuggestions(const blink::WebInputElement& element,
|
||||
std::vector<base::string16>* values,
|
||||
std::vector<base::string16>* labels) {
|
||||
|
@ -45,7 +47,7 @@ void TrimStringVectorForIPC(std::vector<base::string16>* strings) {
|
|||
(*strings)[i].resize(kMaxDataLength);
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
AutofillAgent::AutofillAgent(
|
||||
content::RenderFrame* frame)
|
||||
|
@ -73,10 +75,10 @@ void AutofillAgent::textFieldDidEndEditing(
|
|||
}
|
||||
|
||||
void AutofillAgent::textFieldDidChange(
|
||||
const blink::WebFormControlElement& element) {
|
||||
const blink::WebFormControlElement& element) {
|
||||
if (!IsUserGesture() && !render_frame()->IsPasting())
|
||||
return;
|
||||
|
||||
|
||||
weak_ptr_factory_.InvalidateWeakPtrs();
|
||||
base::ThreadTaskRunnerHandle::Get()->PostTask(
|
||||
FROM_HERE, base::Bind(&AutofillAgent::textFieldDidChangeImpl,
|
||||
|
@ -84,14 +86,14 @@ void AutofillAgent::textFieldDidChange(
|
|||
}
|
||||
|
||||
void AutofillAgent::textFieldDidChangeImpl(
|
||||
const blink::WebFormControlElement& element) {
|
||||
const blink::WebFormControlElement& element) {
|
||||
ShowSuggestionsOptions options;
|
||||
options.requires_caret_at_end = true;
|
||||
ShowSuggestions(element, options);
|
||||
}
|
||||
|
||||
void AutofillAgent::textFieldDidReceiveKeyDown(
|
||||
const blink::WebInputElement& element,
|
||||
const blink::WebInputElement& element,
|
||||
const blink::WebKeyboardEvent& event) {
|
||||
if (event.windowsKeyCode == ui::VKEY_DOWN ||
|
||||
event.windowsKeyCode == ui::VKEY_UP) {
|
||||
|
@ -113,7 +115,7 @@ void AutofillAgent::dataListOptionsChanged(
|
|||
const blink::WebInputElement& element) {
|
||||
if (!element.focused())
|
||||
return;
|
||||
|
||||
|
||||
ShowSuggestionsOptions options;
|
||||
options.requires_caret_at_end = true;
|
||||
ShowSuggestions(element, options);
|
||||
|
@ -136,7 +138,7 @@ void AutofillAgent::ShowSuggestions(
|
|||
if (!input_element->isTextField())
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
blink::WebString value = element.editingValue();
|
||||
if (value.length() > kMaxDataLength ||
|
||||
(!options.autofill_on_empty_values && value.isEmpty()) ||
|
||||
|
@ -146,7 +148,7 @@ void AutofillAgent::ShowSuggestions(
|
|||
HidePopup();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
std::vector<base::string16> data_list_values;
|
||||
std::vector<base::string16> data_list_labels;
|
||||
if (input_element) {
|
||||
|
@ -155,7 +157,7 @@ void AutofillAgent::ShowSuggestions(
|
|||
TrimStringVectorForIPC(&data_list_values);
|
||||
TrimStringVectorForIPC(&data_list_labels);
|
||||
}
|
||||
|
||||
|
||||
ShowPopup(element, data_list_values, data_list_labels);
|
||||
}
|
||||
|
||||
|
@ -196,10 +198,10 @@ void AutofillAgent::ShowPopup(
|
|||
const blink::WebFormControlElement& element,
|
||||
const std::vector<base::string16>& values,
|
||||
const std::vector<base::string16>& labels) {
|
||||
gfx::RectF bounds =
|
||||
gfx::RectF bounds =
|
||||
render_frame_->GetRenderView()->ElementBoundsInWindow(element);
|
||||
Send(new AtomAutofillViewMsg_ShowPopup(
|
||||
web_contents_routing_id_, routing_id(), bounds, values, labels));
|
||||
}
|
||||
|
||||
} // namespace atom
|
||||
} // namespace atom
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
#ifndef ATOM_RENDERER_ATOM_AUTOFILL_AGENT_H_
|
||||
#define ATOM_RENDERER_ATOM_AUTOFILL_AGENT_H_
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "content/public/renderer/render_frame_observer.h"
|
||||
#include "third_party/WebKit/public/web/WebAutofillClient.h"
|
||||
|
@ -14,14 +16,14 @@
|
|||
|
||||
namespace atom {
|
||||
|
||||
class AutofillAgent : public content::RenderFrameObserver,
|
||||
class AutofillAgent : public content::RenderFrameObserver,
|
||||
public blink::WebAutofillClient {
|
||||
public:
|
||||
AutofillAgent(content::RenderFrame* frame);
|
||||
explicit AutofillAgent(content::RenderFrame* frame);
|
||||
|
||||
// content::RenderFrameObserver:
|
||||
void OnDestruct() override;
|
||||
|
||||
|
||||
void DidChangeScrollOffset() override;
|
||||
void FocusedNodeChanged(const blink::WebNode&) override;
|
||||
|
||||
|
@ -31,9 +33,9 @@ class AutofillAgent : public content::RenderFrameObserver,
|
|||
bool autofill_on_empty_values;
|
||||
bool requires_caret_at_end;
|
||||
};
|
||||
|
||||
|
||||
bool OnMessageReceived(const IPC::Message& message) override;
|
||||
void OnWebContentsRoutingIdReceived(int);
|
||||
void OnWebContentsRoutingIdReceived(int routing_id);
|
||||
|
||||
// blink::WebAutofillClient:
|
||||
void textFieldDidEndEditing(const blink::WebInputElement&) override;
|
||||
|
@ -43,7 +45,7 @@ class AutofillAgent : public content::RenderFrameObserver,
|
|||
const blink::WebKeyboardEvent&) override;
|
||||
void openTextDataListChooser(const blink::WebInputElement&) override;
|
||||
void dataListOptionsChanged(const blink::WebInputElement&) override;
|
||||
|
||||
|
||||
bool IsUserGesture() const;
|
||||
void HidePopup();
|
||||
void ShowPopup(const blink::WebFormControlElement&,
|
||||
|
|
Loading…
Reference in a new issue