diff options
author | tony@chromium.org <tony@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-17 18:14:35 +0000 |
---|---|---|
committer | tony@chromium.org <tony@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-17 18:14:35 +0000 |
commit | 8b3e65e627f962338468e6b6dcf556ccda06a4ac (patch) | |
tree | a29b5a3cbecc61c32bee2249bce2509e5c69980b /chrome/browser/gtk | |
parent | 231e7ad8a7d5c1aab39bb6c4b5142787790d0e5f (diff) | |
download | chromium_src-8b3e65e627f962338468e6b6dcf556ccda06a4ac.zip chromium_src-8b3e65e627f962338468e6b6dcf556ccda06a4ac.tar.gz chromium_src-8b3e65e627f962338468e6b6dcf556ccda06a4ac.tar.bz2 |
Add rounded corner support to rounded_window.cc. This only kicks
in if the radius is >= 8, which is the case for the full screen
exit bubble.
We could tweak the radius needed to trigger this-- I didn't actually
test to see what radii looked good and what radii looked bad.
BUG=8405
Review URL: http://codereview.chromium.org/505029
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@34840 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/gtk')
-rw-r--r-- | chrome/browser/gtk/fullscreen_exit_bubble_gtk.cc | 4 | ||||
-rw-r--r-- | chrome/browser/gtk/rounded_window.cc | 101 |
2 files changed, 89 insertions, 16 deletions
diff --git a/chrome/browser/gtk/fullscreen_exit_bubble_gtk.cc b/chrome/browser/gtk/fullscreen_exit_bubble_gtk.cc index c545def..7f90b9a 100644 --- a/chrome/browser/gtk/fullscreen_exit_bubble_gtk.cc +++ b/chrome/browser/gtk/fullscreen_exit_bubble_gtk.cc @@ -8,6 +8,7 @@ #include "app/l10n_util.h" #include "chrome/browser/gtk/gtk_chrome_link_button.h" #include "chrome/browser/gtk/gtk_floating_container.h" +#include "chrome/browser/gtk/rounded_window.h" #include "chrome/common/gtk_util.h" #include "grit/app_strings.h" #include "grit/generated_resources.h" @@ -58,6 +59,9 @@ void FullscreenExitBubbleGtk::InitWidgets() { alignment_.Own(gtk_util::CreateGtkBorderBin(link, &gfx::kGdkBlack, kPaddingPixels, kPaddingPixels, kPaddingPixels, kPaddingPixels)); + gtk_util::ActAsRoundedWindow(alignment_.get(), gfx::kGdkGreen, kPaddingPixels, + gtk_util::ROUNDED_BOTTOM_LEFT | gtk_util::ROUNDED_BOTTOM_RIGHT, + gtk_util::BORDER_NONE); gtk_widget_set_name(alignment_.get(), "exit-fullscreen-bubble"); gtk_widget_show_all(alignment_.get()); diff --git a/chrome/browser/gtk/rounded_window.cc b/chrome/browser/gtk/rounded_window.cc index b6174b4..cb25bd7 100644 --- a/chrome/browser/gtk/rounded_window.cc +++ b/chrome/browser/gtk/rounded_window.cc @@ -5,6 +5,7 @@ #include "chrome/browser/gtk/rounded_window.h" #include <gtk/gtk.h> +#include <math.h> #include "app/l10n_util.h" #include "chrome/common/gtk_util.h" @@ -15,6 +16,10 @@ namespace { const char* kRoundedData = "rounded-window-data"; +// If the border radius is less than |kMinRoundedBorderSize|, we don't actually +// round the corners, we just truncate the corner. +const int kMinRoundedBorderSize = 8; + struct RoundedWindowData { // Expected window size. Used to detect when we need to reshape the window. int expected_width; @@ -66,14 +71,35 @@ std::vector<GdkPoint> MakeFramePolygonPoints(RoundedWindowData* data, // We use this one for RTL. int x_off_r = !ltr ? -y_off : 0; + // Build up points starting with the bottom left corner and continuing + // clockwise. + // Bottom left corner. if (type == FRAME_MASK || (data->drawn_borders & (BORDER_LEFT | BORDER_BOTTOM))) { if (data->rounded_edges & ROUNDED_BOTTOM_LEFT) { - points.push_back(MakeBidiGdkPoint( - corner_size + x_off_l, height + y_off, width, ltr)); - points.push_back(MakeBidiGdkPoint( - x_off_r, height - corner_size, width, ltr)); + if (corner_size >= kMinRoundedBorderSize) { + // We are careful to only add points that are horizontal or vertically + // offset from the previous point (not both). This avoids rounding + // differences when two points are connected. + for (int x = 0; x <= corner_size; ++x) { + int y = static_cast<int>(sqrt(static_cast<double>( + (corner_size * corner_size) - (x * x)))); + if (x > 0) { + points.push_back(MakeBidiGdkPoint( + corner_size - x + x_off_r + 1, + height - (corner_size - y) + y_off, width, ltr)); + } + points.push_back(MakeBidiGdkPoint( + corner_size - x + x_off_r, + height - (corner_size - y) + y_off, width, ltr)); + } + } else { + points.push_back(MakeBidiGdkPoint( + corner_size + x_off_l, height + y_off, width, ltr)); + points.push_back(MakeBidiGdkPoint( + x_off_r, height - corner_size, width, ltr)); + } } else { points.push_back(MakeBidiGdkPoint(x_off_r, height + y_off, width, ltr)); } @@ -83,10 +109,23 @@ std::vector<GdkPoint> MakeFramePolygonPoints(RoundedWindowData* data, if (type == FRAME_MASK || (data->drawn_borders & (BORDER_LEFT | BORDER_TOP))) { if (data->rounded_edges & ROUNDED_TOP_LEFT) { - points.push_back(MakeBidiGdkPoint( - x_off_r, corner_size - 1, width, ltr)); - points.push_back(MakeBidiGdkPoint( - corner_size + x_off_r - 1, 0, width, ltr)); + if (corner_size >= kMinRoundedBorderSize) { + for (int x = corner_size; x >= 0; --x) { + int y = static_cast<int>(sqrt(static_cast<double>( + (corner_size * corner_size) - (x * x)))); + points.push_back(MakeBidiGdkPoint(corner_size - x + x_off_r, + corner_size - y, width, ltr)); + if (x > 0) { + points.push_back(MakeBidiGdkPoint(corner_size - x + 1 + x_off_r, + corner_size - y, width, ltr)); + } + } + } else { + points.push_back(MakeBidiGdkPoint( + x_off_r, corner_size - 1, width, ltr)); + points.push_back(MakeBidiGdkPoint( + corner_size + x_off_r - 1, 0, width, ltr)); + } } else { points.push_back(MakeBidiGdkPoint(x_off_r, 0, width, ltr)); } @@ -96,10 +135,25 @@ std::vector<GdkPoint> MakeFramePolygonPoints(RoundedWindowData* data, if (type == FRAME_MASK || (data->drawn_borders & (BORDER_TOP | BORDER_RIGHT))) { if (data->rounded_edges & ROUNDED_TOP_RIGHT) { - points.push_back(MakeBidiGdkPoint( - width - corner_size + 1 + x_off_l, 0, width, ltr)); - points.push_back(MakeBidiGdkPoint( - width + x_off_l, corner_size - 1, width, ltr)); + if (corner_size >= kMinRoundedBorderSize) { + for (int x = 0; x <= corner_size; ++x) { + int y = static_cast<int>(sqrt(static_cast<double>( + (corner_size * corner_size) - (x * x)))); + if (x > 0) { + points.push_back(MakeBidiGdkPoint( + width - (corner_size - x) + x_off_l - 1, + corner_size - y, width, ltr)); + } + points.push_back(MakeBidiGdkPoint( + width - (corner_size - x) + x_off_l, + corner_size - y, width, ltr)); + } + } else { + points.push_back(MakeBidiGdkPoint( + width - corner_size + 1 + x_off_l, 0, width, ltr)); + points.push_back(MakeBidiGdkPoint( + width + x_off_l, corner_size - 1, width, ltr)); + } } else { points.push_back(MakeBidiGdkPoint( width + x_off_l, 0, width, ltr)); @@ -110,10 +164,25 @@ std::vector<GdkPoint> MakeFramePolygonPoints(RoundedWindowData* data, if (type == FRAME_MASK || (data->drawn_borders & (BORDER_RIGHT | BORDER_BOTTOM))) { if (data->rounded_edges & ROUNDED_BOTTOM_RIGHT) { - points.push_back(MakeBidiGdkPoint( - width + x_off_l, height - corner_size, width, ltr)); - points.push_back(MakeBidiGdkPoint( - width - corner_size + x_off_r, height + y_off, width, ltr)); + if (corner_size >= kMinRoundedBorderSize) { + for (int x = corner_size; x >= 0; --x) { + int y = static_cast<int>(sqrt(static_cast<double>( + (corner_size * corner_size) - (x * x)))); + points.push_back(MakeBidiGdkPoint( + width - (corner_size - x) + x_off_l, + height - (corner_size - y) + y_off, width, ltr)); + if (x > 0) { + points.push_back(MakeBidiGdkPoint( + width - (corner_size - x) + x_off_l - 1, + height - (corner_size - y) + y_off, width, ltr)); + } + } + } else { + points.push_back(MakeBidiGdkPoint( + width + x_off_l, height - corner_size, width, ltr)); + points.push_back(MakeBidiGdkPoint( + width - corner_size + x_off_r, height + y_off, width, ltr)); + } } else { points.push_back(MakeBidiGdkPoint( width + x_off_l, height + y_off, width, ltr)); |