Commit 77f529bd authored by Luciano Pacheco's avatar Luciano Pacheco Committed by Commit Bot

Refactor ExtensionDialog::InitParams to use gfx::Size

Follow up work from CL:2126340.

Fix #include problems pointed by "git cl lint".

Bug: 1064822
Change-Id: Ia393c4f82601007e198d37ae9a7fcb1aae915bf3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2148980
Commit-Queue: Luciano Pacheco <lucmult@chromium.org>
Auto-Submit: Luciano Pacheco <lucmult@chromium.org>
Reviewed-by: default avatarDevlin <rdevlin.cronin@chromium.org>
Reviewed-by: default avatarJames Cook <jamescook@chromium.org>
Cr-Commit-Position: refs/heads/master@{#759869}
parent 76ff8659
...@@ -37,8 +37,8 @@ ...@@ -37,8 +37,8 @@
using content::BrowserContext; using content::BrowserContext;
using content::WebContents; using content::WebContents;
ExtensionDialog::InitParams::InitParams(int width, int height) ExtensionDialog::InitParams::InitParams(gfx::Size size)
: width(width), height(height) {} : size(std::move(size)) {}
ExtensionDialog::InitParams::InitParams(const InitParams& other) = default; ExtensionDialog::InitParams::InitParams(const InitParams& other) = default;
ExtensionDialog::InitParams::~InitParams() = default; ExtensionDialog::InitParams::~InitParams() = default;
...@@ -56,9 +56,8 @@ ExtensionDialog* ExtensionDialog::Show(const GURL& url, ...@@ -56,9 +56,8 @@ ExtensionDialog* ExtensionDialog::Show(const GURL& url,
// Preferred size must be set before views::Widget::CreateWindowWithParent() // Preferred size must be set before views::Widget::CreateWindowWithParent()
// is called because CreateWindowWithParent() references CanResize(). // is called because CreateWindowWithParent() references CanResize().
ExtensionViewViews* view = GetExtensionView(host.get()); ExtensionViewViews* view = GetExtensionView(host.get());
view->SetPreferredSize(gfx::Size(init_params.width, init_params.height)); view->SetPreferredSize(init_params.size);
view->set_minimum_size( view->set_minimum_size(init_params.min_size);
gfx::Size(init_params.min_width, init_params.min_height));
host->SetAssociatedWebContents(web_contents); host->SetAssociatedWebContents(web_contents);
DCHECK(parent_window); DCHECK(parent_window);
...@@ -214,16 +213,18 @@ void ExtensionDialog::InitWindow(gfx::NativeWindow parent, ...@@ -214,16 +213,18 @@ void ExtensionDialog::InitWindow(gfx::NativeWindow parent,
gfx::Rect bounds = parent ? views::Widget::GetWidgetForNativeWindow(parent) gfx::Rect bounds = parent ? views::Widget::GetWidgetForNativeWindow(parent)
->GetWindowBoundsInScreen() ->GetWindowBoundsInScreen()
: screen_rect; : screen_rect;
bounds.ClampToCenteredSize({init_params.width, init_params.height}); bounds.ClampToCenteredSize(init_params.size);
// Make sure bounds is larger than {min_width, min_height}. // Make sure bounds is larger than {min_size}.
if (bounds.width() < init_params.min_width) { if (bounds.width() < init_params.min_size.width()) {
bounds.set_x(bounds.x() + (bounds.width() - init_params.min_width) / 2); bounds.set_x(bounds.x() +
bounds.set_width(init_params.min_width); (bounds.width() - init_params.min_size.width()) / 2);
bounds.set_width(init_params.min_size.width());
} }
if (bounds.height() < init_params.min_height) { if (bounds.height() < init_params.min_size.height()) {
bounds.set_y(bounds.y() + (bounds.height() - init_params.min_height) / 2); bounds.set_y(bounds.y() +
bounds.set_height(init_params.min_height); (bounds.height() - init_params.min_size.height()) / 2);
bounds.set_height(init_params.min_size.height());
} }
// Make sure bounds is still on screen. // Make sure bounds is still on screen.
......
...@@ -39,18 +39,21 @@ class ExtensionDialog : public views::DialogDelegate, ...@@ -39,18 +39,21 @@ class ExtensionDialog : public views::DialogDelegate,
public base::RefCounted<ExtensionDialog> { public base::RefCounted<ExtensionDialog> {
public: public:
struct InitParams { struct InitParams {
InitParams(int width, int height); // |size| Size in DIP (Device Independent Pixel) for the dialog window.
explicit InitParams(gfx::Size size);
InitParams(const InitParams& other); InitParams(const InitParams& other);
~InitParams(); ~InitParams();
// |is_modal| determines whether the dialog is modal to |parent_window|. // |is_modal| determines whether the dialog is modal to |parent_window|.
bool is_modal = false; bool is_modal = false;
// |width| and |height| are the size of the dialog in pixels. // Size in DIP (Device Independent Pixel) for the dialog window.
int width = 0; gfx::Size size;
int height = 0;
int min_width = 0; // Minimum size in DIP (Device Independent Pixel) for the dialog window.
int min_height = 0; gfx::Size min_size;
// Text for the dialog title, it should be already localized.
base::string16 title; base::string16 title;
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
......
...@@ -54,10 +54,9 @@ class ExtensionDialogBoundsTest ...@@ -54,10 +54,9 @@ class ExtensionDialogBoundsTest
// Dimensions of a dialog that would be bigger than the remaining display // Dimensions of a dialog that would be bigger than the remaining display
// work area when the docked magnifier is enabled. // work area when the docked magnifier is enabled.
ExtensionDialog::InitParams params(1000, 1000); ExtensionDialog::InitParams params(gfx::Size(1000, 1000));
params.is_modal = true; params.is_modal = true;
params.min_width = 640; params.min_size = {640, 240};
params.min_height = 240;
auto* dialog = ExtensionDialog::Show( auto* dialog = ExtensionDialog::Show(
extension->url().Resolve("main.html"), extension->url().Resolve("main.html"),
browser()->window()->GetNativeWindow(), browser()->profile(), browser()->window()->GetNativeWindow(), browser()->profile(),
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include "chrome/browser/extensions/extension_view_host.h" #include "chrome/browser/extensions/extension_view_host.h"
#include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/views/content_test_utils.h" #include "chrome/browser/ui/views/content_test_utils.h"
#include "chrome/browser/ui/views/extensions/extension_dialog.h"
#include "extensions/test/extension_test_message_listener.h" #include "extensions/test/extension_test_message_listener.h"
namespace { namespace {
...@@ -22,10 +21,9 @@ IN_PROC_BROWSER_TEST_F(ExtensionDialogTest, TextInputViaKeyEvent) { ...@@ -22,10 +21,9 @@ IN_PROC_BROWSER_TEST_F(ExtensionDialogTest, TextInputViaKeyEvent) {
LoadExtension(test_data_dir_.AppendASCII("uitest/tab_traversal")); LoadExtension(test_data_dir_.AppendASCII("uitest/tab_traversal"));
ASSERT_TRUE(extension.get()); ASSERT_TRUE(extension.get());
ExtensionDialog::InitParams params(400, 300); ExtensionDialog::InitParams params(gfx::Size(400, 300));
params.is_modal = true; params.is_modal = true;
params.min_width = 400; params.min_size = {400, 300};
params.min_height = 300;
auto* dialog = ExtensionDialog::Show( auto* dialog = ExtensionDialog::Show(
extension->url().Resolve("main.html"), extension->url().Resolve("main.html"),
browser()->window()->GetNativeWindow(), browser()->profile(), browser()->window()->GetNativeWindow(), browser()->profile(),
......
...@@ -44,10 +44,9 @@ IN_PROC_BROWSER_TEST_F(ExtensionDialogUiTest, MAYBE_TabFocusLoop) { ...@@ -44,10 +44,9 @@ IN_PROC_BROWSER_TEST_F(ExtensionDialogUiTest, MAYBE_TabFocusLoop) {
// Open ExtensionDialog, whose initial page is the extension's main.html. // Open ExtensionDialog, whose initial page is the extension's main.html.
// The main.html contains three buttons. // The main.html contains three buttons.
ExtensionDialog::InitParams params(300, 300); ExtensionDialog::InitParams params(gfx::Size(300, 300));
params.is_modal = true; params.is_modal = true;
params.min_width = 300; params.min_size = {300, 300};
params.min_height = 300;
ExtensionDialog* dialog = ExtensionDialog* dialog =
ExtensionDialog::Show(extension->url().Resolve("main.html"), ExtensionDialog::Show(extension->url().Resolve("main.html"),
browser()->window()->GetNativeWindow(), browser()->window()->GetNativeWindow(),
......
...@@ -4,6 +4,11 @@ ...@@ -4,6 +4,11 @@
#include "chrome/browser/ui/views/select_file_dialog_extension.h" #include "chrome/browser/ui/views/select_file_dialog_extension.h"
#include <map>
#include <memory>
#include <string>
#include <utility>
#include "base/bind.h" #include "base/bind.h"
#include "base/callback.h" #include "base/callback.h"
#include "base/location.h" #include "base/location.h"
...@@ -400,11 +405,11 @@ void SelectFileDialogExtension::SelectFileWithFileManagerParams( ...@@ -400,11 +405,11 @@ void SelectFileDialogExtension::SelectFileWithFileManagerParams(
default_path.BaseName().value(), file_types, file_type_index, default_path.BaseName().value(), file_types, file_type_index,
default_extension, show_android_picker_apps); default_extension, show_android_picker_apps);
ExtensionDialog::InitParams dialog_params(kFileManagerWidth, ExtensionDialog::InitParams dialog_params(
kFileManagerHeight); {kFileManagerWidth, kFileManagerHeight});
dialog_params.is_modal = (owner_window != nullptr); dialog_params.is_modal = (owner_window != nullptr);
dialog_params.min_width = kFileManagerMinimumWidth; dialog_params.min_size = {kFileManagerMinimumWidth,
dialog_params.min_height = kFileManagerMinimumHeight; kFileManagerMinimumHeight};
dialog_params.title = file_manager::util::GetSelectFileDialogTitle(type); dialog_params.title = file_manager::util::GetSelectFileDialogTitle(type);
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
if (base::FeatureList::IsEnabled(chromeos::features::kFilesNG)) { if (base::FeatureList::IsEnabled(chromeos::features::kFilesNG)) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment