summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authordimich@chromium.org <dimich@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-24 02:27:00 +0000
committerdimich@chromium.org <dimich@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-24 02:27:00 +0000
commit4ad76a8bc1b04e5b27a18f336534b70ddf41f9a1 (patch)
treea0f9250d677e76e51a9c35385347a771cd9af95e /chrome
parentf34dabdeb6ff9e25515bb68bac78af7f49ce6f3a (diff)
downloadchromium_src-4ad76a8bc1b04e5b27a18f336534b70ddf41f9a1.zip
chromium_src-4ad76a8bc1b04e5b27a18f336534b70ddf41f9a1.tar.gz
chromium_src-4ad76a8bc1b04e5b27a18f336534b70ddf41f9a1.tar.bz2
Reduce minimum size of Panels to allow 1-text-line tight autosize.
BUG=102708 TEST=PanelBrowserTest.SizeClamping This patch does not attempt to calculate the actual size of titlebar and text line on a particular machine, just changes defaults to more accommodating. Instead of 100x100 we now have 100x20. Width of 100 seems to be a good arbitrary value that allows reasonable rendering of titlebar with close button, favicon and few characters of title text. Height of 20 allows auto-sizing to tightly wrap around small content (like a text line) Review URL: http://codereview.chromium.org/8621002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@111480 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/ui/panels/panel_browsertest.cc63
-rw-r--r--chrome/browser/ui/panels/panel_manager.cc4
-rw-r--r--chrome/browser/ui/panels/panel_manager.h12
-rw-r--r--chrome/test/data/extensions/api_test/window_update/show_state/test.html4
-rw-r--r--chrome/test/data/panels/update-preferred-size.html2
5 files changed, 77 insertions, 8 deletions
diff --git a/chrome/browser/ui/panels/panel_browsertest.cc b/chrome/browser/ui/panels/panel_browsertest.cc
index 78a8a6d..82c27f2 100644
--- a/chrome/browser/ui/panels/panel_browsertest.cc
+++ b/chrome/browser/ui/panels/panel_browsertest.cc
@@ -881,7 +881,7 @@ IN_PROC_BROWSER_TEST_F(PanelBrowserTest, RestoredBounds) {
// Disable mouse watcher. We don't care about mouse movements in this test.
PanelManager* panel_manager = PanelManager::GetInstance();
panel_manager->disable_mouse_watching();
- Panel* panel = CreatePanel("PanelTest");
+ Panel* panel = CreatePanelWithBounds("PanelTest", gfx::Rect(0, 0, 100, 100));
EXPECT_EQ(Panel::EXPANDED, panel->expansion_state());
EXPECT_EQ(panel->GetBounds(), panel->GetRestoredBounds());
EXPECT_EQ(0, panel_manager->minimized_panel_count());
@@ -1495,6 +1495,67 @@ IN_PROC_BROWSER_TEST_F(PanelBrowserTest, CreateWithExistingContents) {
tabbed_browser->window()->Close();
}
+IN_PROC_BROWSER_TEST_F(PanelBrowserTest, SizeClamping) {
+ // Using '0' sizes is equivalent of not providing sizes in API and causes
+ // minimum sizes to be applied to facilitate auto-sizing.
+ CreatePanelParams params("Panel", gfx::Rect(), SHOW_AS_ACTIVE);
+ Panel* panel = CreatePanelWithParams(params);
+ EXPECT_EQ(PanelManager::kPanelMinWidth, panel->GetBounds().width());
+ EXPECT_EQ(PanelManager::kPanelMinHeight, panel->GetBounds().height());
+ panel->Close();
+
+ // Using reasonable actual sizes should avoid clamping.
+ int reasonable_width = PanelManager::kPanelMinWidth + 10;
+ int reasonable_height = PanelManager::kPanelMinHeight + 20;
+ CreatePanelParams params1("Panel1",
+ gfx::Rect(0, 0,
+ reasonable_width, reasonable_height),
+ SHOW_AS_ACTIVE);
+ panel = CreatePanelWithParams(params1);
+ EXPECT_EQ(reasonable_width, panel->GetBounds().width());
+ EXPECT_EQ(reasonable_height, panel->GetBounds().height());
+ panel->Close();
+
+ // Using just one size should auto-compute some reasonable other size.
+ int given_height = 200;
+ CreatePanelParams params2("Panel2", gfx::Rect(0, 0, 0, given_height),
+ SHOW_AS_ACTIVE);
+ panel = CreatePanelWithParams(params2);
+ EXPECT_GT(panel->GetBounds().width(), 0);
+ EXPECT_EQ(given_height, panel->GetBounds().height());
+ panel->Close();
+}
+
+IN_PROC_BROWSER_TEST_F(PanelBrowserTest, TightAutosizeAroundSingleLine) {
+ PanelManager::GetInstance()->enable_auto_sizing(true);
+ // Using 0 sizes triggers auto-sizing.
+ CreatePanelParams params("Panel", gfx::Rect(), SHOW_AS_ACTIVE);
+ params.url = GURL("data:text/html;charset=utf-8,<!doctype html><body>");
+ Panel* panel = CreatePanelWithParams(params);
+
+ int initial_width = panel->GetBounds().width();
+ int initial_height = panel->GetBounds().height();
+
+ // Inject some HTML content into the panel.
+ ui_test_utils::WindowedNotificationObserver enlarge(
+ chrome::NOTIFICATION_PANEL_BOUNDS_ANIMATIONS_FINISHED,
+ content::Source<Panel>(panel));
+ EXPECT_TRUE(ui_test_utils::ExecuteJavaScript(
+ panel->browser()->GetSelectedTabContents()->render_view_host(),
+ std::wstring(),
+ L"document.body.innerHTML ="
+ L"'<nobr>line of text and a <button>Button</button>';"));
+ enlarge.Wait();
+
+ // The panel should have become larger in both dimensions (the minimums
+ // has to be set to be smaller then a simple 1-line content, so the autosize
+ // can work correctly.
+ EXPECT_GT(panel->GetBounds().width(), initial_width);
+ EXPECT_GT(panel->GetBounds().height(), initial_height);
+
+ panel->Close();
+}
+
class PanelDownloadTest : public PanelBrowserTest {
public:
PanelDownloadTest() : PanelBrowserTest() { }
diff --git a/chrome/browser/ui/panels/panel_manager.cc b/chrome/browser/ui/panels/panel_manager.cc
index 5e3b9ad..0a89167 100644
--- a/chrome/browser/ui/panels/panel_manager.cc
+++ b/chrome/browser/ui/panels/panel_manager.cc
@@ -50,6 +50,10 @@ const int kMillisecondsBeforeCollapsingFromTitleOnlyState = 0;
} // namespace
// static
+const int PanelManager::kPanelMinWidth = 100;
+const int PanelManager::kPanelMinHeight = 20;
+
+// static
PanelManager* PanelManager::GetInstance() {
static base::LazyInstance<PanelManager> instance = LAZY_INSTANCE_INITIALIZER;
return instance.Pointer();
diff --git a/chrome/browser/ui/panels/panel_manager.h b/chrome/browser/ui/panels/panel_manager.h
index 0e0d3cb..5c3a92f 100644
--- a/chrome/browser/ui/panels/panel_manager.h
+++ b/chrome/browser/ui/panels/panel_manager.h
@@ -118,6 +118,7 @@ class PanelManager : public PanelMouseWatcher::Observer,
private:
friend struct base::DefaultLazyInstanceTraits<PanelManager>;
+ FRIEND_TEST_ALL_PREFIXES(PanelBrowserTest, SizeClamping);
enum TitlebarAction {
NO_ACTION,
@@ -221,12 +222,11 @@ class PanelManager : public PanelMouseWatcher::Observer,
static const int kPanelsHorizontalSpacing = 4;
- // Minimum width and height of a panel.
- // Note: The minimum size of a widget (see widget.cc) is fixed to 100x100.
- // TODO(jianli): Need to fix this to support smaller panel.
- // http://crbug.com/102708
- static const int kPanelMinWidth = 100;
- static const int kPanelMinHeight = 100;
+ // Absolute minimum width and height for panels, including non-client area.
+ // Should only be big enough to accomodate a close button on the reasonably
+ // recognisable titlebar.
+ static const int kPanelMinWidth;
+ static const int kPanelMinHeight;
DISALLOW_COPY_AND_ASSIGN(PanelManager);
};
diff --git a/chrome/test/data/extensions/api_test/window_update/show_state/test.html b/chrome/test/data/extensions/api_test/window_update/show_state/test.html
index d463531..996f890 100644
--- a/chrome/test/data/extensions/api_test/window_update/show_state/test.html
+++ b/chrome/test/data/extensions/api_test/window_update/show_state/test.html
@@ -58,7 +58,9 @@ function minimizeWindow(theWindow) {
}
function testWindowState(windowType) {
- chrome.windows.create({'url': 'hello.html', 'type': windowType},
+ // Specifying size prevents 'panel' windows from computing size asynchronously. It ensures
+ // panel sizes stay fixed through the test.
+ chrome.windows.create({'url': 'hello.html', 'type': windowType, 'width':100, 'height':100 },
pass(minimizeWindow));
}
diff --git a/chrome/test/data/panels/update-preferred-size.html b/chrome/test/data/panels/update-preferred-size.html
index 76e3f3f..5edc351 100644
--- a/chrome/test/data/panels/update-preferred-size.html
+++ b/chrome/test/data/panels/update-preferred-size.html
@@ -1,3 +1,5 @@
+<!-- the Doctype PI turns off 'quirks mode' in HTML layout and makes auto-sizing work right. -->
+<!doctype html>
<html>
<head>