From 7e0593950cf8da260a812e9a812f1e2ac6f22534 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 13 Nov 2017 16:13:54 +0900 Subject: [PATCH] Code style fixes --- atom/browser/api/atom_api_web_contents.cc | 22 ++++++------- atom/browser/api/atom_api_web_contents.h | 9 +++-- atom/browser/api/atom_api_window.cc | 2 +- .../browser/atom_download_manager_delegate.cc | 2 +- atom/browser/common_web_contents_delegate.cc | 12 +++---- atom/browser/native_window.h | 10 ++---- atom/browser/native_window_views.cc | 17 +++++----- atom/browser/ui/autofill_popup.cc | 33 ++++++++++--------- atom/browser/ui/message_box_mac.mm | 4 +-- atom/browser/web_dialog_helper.h | 2 +- 10 files changed, 56 insertions(+), 57 deletions(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index bb815c3a2345..4bc6c081023f 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -909,6 +909,17 @@ void WebContents::DevToolsClosed() { Emit("devtools-closed"); } +void WebContents::ShowAutofillPopup(content::RenderFrameHost* frame_host, + const gfx::RectF& bounds, + const std::vector& values, + const std::vector& labels) { + auto relay = NativeWindowRelay::FromWebContents(web_contents()); + if (relay) { + relay->window->ShowAutofillPopup( + frame_host, web_contents(), bounds, values, labels); + } +} + bool WebContents::OnMessageReceived(const IPC::Message& message) { bool handled = true; IPC_BEGIN_MESSAGE_MAP(WebContents, message) @@ -945,17 +956,6 @@ bool WebContents::OnMessageReceived(const IPC::Message& message, return handled; } -void WebContents::ShowAutofillPopup( - content::RenderFrameHost* frame_host, - const gfx::RectF& bounds, - const std::vector& values, - const std::vector& labels) { - auto relay = NativeWindowRelay::FromWebContents(web_contents()); - if (relay) - relay->window->ShowAutofillPopup( - frame_host, web_contents(), bounds, values, labels); -} - // There are three ways of destroying a webContents: // 1. call webContents.destroy(); // 2. garbage collection; diff --git a/atom/browser/api/atom_api_web_contents.h b/atom/browser/api/atom_api_web_contents.h index 2949905f1761..ffeb8f724180 100644 --- a/atom/browser/api/atom_api_web_contents.h +++ b/atom/browser/api/atom_api_web_contents.h @@ -357,11 +357,10 @@ class WebContents : public mate::TrackableObject, void DevToolsOpened() override; void DevToolsClosed() override; - void ShowAutofillPopup( - content::RenderFrameHost* frame_host, - const gfx::RectF& bounds, - const std::vector& values, - const std::vector& labels); + void ShowAutofillPopup(content::RenderFrameHost* frame_host, + const gfx::RectF& bounds, + const std::vector& values, + const std::vector& labels); private: AtomBrowserContext* GetBrowserContext() const; diff --git a/atom/browser/api/atom_api_window.cc b/atom/browser/api/atom_api_window.cc index c4acc04b4e4f..bb7060adb76d 100644 --- a/atom/browser/api/atom_api_window.cc +++ b/atom/browser/api/atom_api_window.cc @@ -144,7 +144,7 @@ void Window::Init(v8::Isolate* isolate, options, parent.IsEmpty() ? nullptr : parent->window_.get())); web_contents->SetOwnerWindow(window_.get()); - window_->SetIsOffScreenDummy(api_web_contents_->IsOffScreen()); + window_->set_is_offscreen_dummy(api_web_contents_->IsOffScreen()); #if defined(TOOLKIT_VIEWS) // Sets the window icon. diff --git a/atom/browser/atom_download_manager_delegate.cc b/atom/browser/atom_download_manager_delegate.cc index 5ed9ca8d981b..de9c64ce8ad9 100644 --- a/atom/browser/atom_download_manager_delegate.cc +++ b/atom/browser/atom_download_manager_delegate.cc @@ -92,7 +92,7 @@ void AtomDownloadManagerDelegate::OnDownloadPathGenerated( // Show save dialog if save path was not set already on item file_dialog::DialogSettings settings; settings.parent_window = window; - settings.force_detached = window->IsOffScreenDummy(); + settings.force_detached = window->is_offscreen_dummy(); settings.title = item->GetURL().spec(); settings.default_path = default_path; if (path.empty() && file_dialog::ShowSaveDialog(settings, &path)) { diff --git a/atom/browser/common_web_contents_delegate.cc b/atom/browser/common_web_contents_delegate.cc index f282acf4c9e5..4075cc9571a0 100644 --- a/atom/browser/common_web_contents_delegate.cc +++ b/atom/browser/common_web_contents_delegate.cc @@ -242,8 +242,8 @@ void CommonWebContentsDelegate::RunFileChooser( content::RenderFrameHost* render_frame_host, const content::FileChooserParams& params) { if (!web_dialog_helper_) - web_dialog_helper_.reset(new WebDialogHelper(owner_window(), - owner_window()->IsOffScreenDummy())); + web_dialog_helper_.reset(new WebDialogHelper( + owner_window(), owner_window()->is_offscreen_dummy())); web_dialog_helper_->RunFileChooser(render_frame_host, params); } @@ -251,8 +251,8 @@ void CommonWebContentsDelegate::EnumerateDirectory(content::WebContents* guest, int request_id, const base::FilePath& path) { if (!web_dialog_helper_) - web_dialog_helper_.reset(new WebDialogHelper(owner_window(), - owner_window()->IsOffScreenDummy())); + web_dialog_helper_.reset(new WebDialogHelper( + owner_window(), owner_window()->is_offscreen_dummy())); web_dialog_helper_->EnumerateDirectory(guest, request_id, path); } @@ -300,7 +300,7 @@ void CommonWebContentsDelegate::DevToolsSaveToFile( } else { file_dialog::DialogSettings settings; settings.parent_window = owner_window(); - settings.force_detached = owner_window()->IsOffScreenDummy(); + settings.force_detached = owner_window()->is_offscreen_dummy(); settings.title = url; settings.default_path = base::FilePath::FromUTF8Unsafe(url); if (!file_dialog::ShowSaveDialog(settings, &path)) { @@ -367,7 +367,7 @@ void CommonWebContentsDelegate::DevToolsAddFileSystem( std::vector paths; file_dialog::DialogSettings settings; settings.parent_window = owner_window(); - settings.force_detached = owner_window()->IsOffScreenDummy(); + settings.force_detached = owner_window()->is_offscreen_dummy(); settings.properties = file_dialog::FILE_DIALOG_OPEN_DIRECTORY; if (!file_dialog::ShowOpenDialog(settings, &paths)) return; diff --git a/atom/browser/native_window.h b/atom/browser/native_window.h index 0c0b50483dcb..1e02a37fc07d 100644 --- a/atom/browser/native_window.h +++ b/atom/browser/native_window.h @@ -10,7 +10,6 @@ #include #include -#include "atom/browser/api/atom_api_web_contents.h" #include "atom/browser/native_window_observer.h" #include "atom/browser/ui/accelerator_util.h" #include "atom/browser/ui/atom_menu_model.h" @@ -237,12 +236,6 @@ class NativeWindow : public base::SupportsUserData, const std::vector& values, const std::vector& labels) {} virtual void HideAutofillPopup(content::RenderFrameHost* frame_host) {} - void SetIsOffScreenDummy(bool is_dummy) { - is_osr_dummy_ = is_dummy; - } - bool IsOffScreenDummy() { - return is_osr_dummy_; - } // Public API used by platform-dependent delegates and observers to send UI // related notifications. @@ -296,6 +289,9 @@ class NativeWindow : public base::SupportsUserData, SkRegion* draggable_region() const { return draggable_region_.get(); } bool enable_larger_than_screen() const { return enable_larger_than_screen_; } + void set_is_offscreen_dummy(bool is_dummy) { is_osr_dummy_ = is_dummy; } + bool is_offscreen_dummy() const { return is_osr_dummy_; } + NativeWindow* parent() const { return parent_; } bool is_modal() const { return is_modal_; } diff --git a/atom/browser/native_window_views.cc b/atom/browser/native_window_views.cc index 31909961f031..efe3ba0fb77b 100644 --- a/atom/browser/native_window_views.cc +++ b/atom/browser/native_window_views.cc @@ -1363,17 +1363,18 @@ void NativeWindowViews::ShowAutofillPopup( const std::vector& values, const std::vector& labels) { WebContentsPreferences* web_preferences = - WebContentsPreferences::FromWebContents(web_contents); + WebContentsPreferences::FromWebContents(web_contents); - bool isOffsceen = web_preferences->IsOffScreen(web_contents); - bool isEmbedderOffscreen = web_preferences->IsGuest(web_contents) && - web_preferences->IsOffScreen(web_preferences->Embedder(web_contents)); + bool is_offsceen = web_preferences->IsOffScreen(web_contents); + bool is_embedder_offscreen = + web_preferences->IsGuest(web_contents) && + web_preferences->IsOffScreen(web_preferences->Embedder(web_contents)); autofill_popup_->CreateView( - frame_host, - isOffsceen || isEmbedderOffscreen, - widget(), - bounds); + frame_host, + is_offsceen || is_embedder_offscreen, + widget(), + bounds); autofill_popup_->SetItems(values, labels); autofill_popup_->UpdatePopupBounds(menu_bar_visible_ ? 0 : kMenuBarHeight); } diff --git a/atom/browser/ui/autofill_popup.cc b/atom/browser/ui/autofill_popup.cc index 7c43f56a036d..f6dc695ec63d 100644 --- a/atom/browser/ui/autofill_popup.cc +++ b/atom/browser/ui/autofill_popup.cc @@ -171,33 +171,36 @@ void AutofillPopup::UpdatePopupBounds(int height_compensation) { bool is_rtl = false; gfx::Point origin(element_bounds_.origin().x(), - element_bounds_.origin().y() - height_compensation); + 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); + 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 // element and grows to the right (since the is the lowest and furthest right // the popup could go). - gfx::Point bottom_right_corner_of_popup = origin + - gfx::Vector2d(desired_width, bounds.height() + desired_height); + gfx::Point bottom_right_corner_of_popup = + 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, container_view_); display::Display bottom_right_display = - GetDisplayNearestPoint(bottom_right_corner_of_popup, container_view_); + GetDisplayNearestPoint(bottom_right_corner_of_popup, container_view_); std::pair popup_x_and_width = - CalculatePopupXAndWidth(top_left_display, bottom_right_display, - desired_width, bounds, is_rtl); - std::pair popup_y_and_height = CalculatePopupYAndHeight( - top_left_display, bottom_right_display, desired_height, bounds); + CalculatePopupXAndWidth(top_left_display, bottom_right_display, + desired_width, bounds, is_rtl); + std::pair popup_y_and_height = + CalculatePopupYAndHeight(top_left_display, bottom_right_display, + desired_height, bounds); - 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_bounds_in_view_ = gfx::Rect(popup_bounds_in_view_.origin(), - gfx::Size(popup_x_and_width.second, popup_y_and_height.second)); + 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_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(); } diff --git a/atom/browser/ui/message_box_mac.mm b/atom/browser/ui/message_box_mac.mm index c116a2da3a05..8f495f3bf7af 100644 --- a/atom/browser/ui/message_box_mac.mm +++ b/atom/browser/ui/message_box_mac.mm @@ -147,7 +147,7 @@ int ShowMessageBox(NativeWindow* parent_window, // Use runModal for synchronous alert without parent, since we don't have a // window to wait for. if (!parent_window || !parent_window->GetNativeWindow() || - parent_window->IsOffScreenDummy()) + parent_window->is_offscreen_dummy()) return [[alert autorelease] runModal]; int ret_code = -1; @@ -186,7 +186,7 @@ void ShowMessageBox(NativeWindow* parent_window, // Use runModal for synchronous alert without parent, since we don't have a // window to wait for. if (!parent_window || !parent_window->GetNativeWindow() || - parent_window->IsOffScreenDummy()) { + parent_window->is_offscreen_dummy()) { int ret = [[alert autorelease] runModal]; callback.Run(ret, false); } else { diff --git a/atom/browser/web_dialog_helper.h b/atom/browser/web_dialog_helper.h index 8f4963fa0b0b..9165b5961399 100644 --- a/atom/browser/web_dialog_helper.h +++ b/atom/browser/web_dialog_helper.h @@ -23,7 +23,7 @@ class NativeWindow; class WebDialogHelper { public: - explicit WebDialogHelper(NativeWindow* window, bool offscreen); + WebDialogHelper(NativeWindow* window, bool offscreen); ~WebDialogHelper(); void RunFileChooser(content::RenderFrameHost* render_frame_host,