diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-02 21:49:12 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-02 21:49:12 +0000 |
commit | f00fa4d766ac76419a051345a496caecfbeddc78 (patch) | |
tree | b742fc1bdaa6dfd815e3b8ad719789572bb23398 /chrome | |
parent | 50d7d7283db42b531a9df9c6f5a34b8526d4d5b0 (diff) | |
download | chromium_src-f00fa4d766ac76419a051345a496caecfbeddc78.zip chromium_src-f00fa4d766ac76419a051345a496caecfbeddc78.tar.gz chromium_src-f00fa4d766ac76419a051345a496caecfbeddc78.tar.bz2 |
Fix bookmark and menu drag images by making a halo around them. This makes
the ClearType composited on the correct color to fix the semitransparent pixels
into 1-bit transparency pixels.
Remove some unnecessary header file dependencies on ChromeCanvas I noticed
when compiling this patch.
BUG=8258
Review URL: http://codereview.chromium.org/27321
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@10732 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
24 files changed, 158 insertions, 33 deletions
diff --git a/chrome/browser/renderer_host/render_widget_host_view_win.cc b/chrome/browser/renderer_host/render_widget_host_view_win.cc index 66a1694..e0ed23e 100644 --- a/chrome/browser/renderer_host/render_widget_host_view_win.cc +++ b/chrome/browser/renderer_host/render_widget_host_view_win.cc @@ -17,6 +17,7 @@ #include "chrome/browser/renderer_host/render_widget_host.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_switches.h" +#include "chrome/common/gfx/chrome_canvas.h" #include "chrome/common/l10n_util.h" #include "chrome/common/l10n_util_win.h" #include "chrome/common/plugin_messages.h" diff --git a/chrome/browser/views/frame/aero_glass_non_client_view.cc b/chrome/browser/views/frame/aero_glass_non_client_view.cc index b3036ed..93031d1 100644 --- a/chrome/browser/views/frame/aero_glass_non_client_view.cc +++ b/chrome/browser/views/frame/aero_glass_non_client_view.cc @@ -6,6 +6,7 @@ #include "chrome/browser/views/frame/browser_view.h" #include "chrome/browser/views/tabs/tab_strip.h" +#include "chrome/common/gfx/chrome_canvas.h" #include "chrome/common/resource_bundle.h" #include "chrome/views/client_view.h" #include "chrome/views/window_resources.h" diff --git a/chrome/browser/views/frame/browser_view.cc b/chrome/browser/views/frame/browser_view.cc index e8cb64a..f287485 100644 --- a/chrome/browser/views/frame/browser_view.cc +++ b/chrome/browser/views/frame/browser_view.cc @@ -42,6 +42,7 @@ #include "chrome/browser/window_sizer.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/drag_drop_types.h" +#include "chrome/common/gfx/chrome_canvas.h" #include "chrome/common/l10n_util.h" #include "chrome/common/notification_service.h" #include "chrome/common/os_exchange_data.h" diff --git a/chrome/browser/views/frame/opaque_non_client_view.cc b/chrome/browser/views/frame/opaque_non_client_view.cc index 48d88db..2ed23f8 100644 --- a/chrome/browser/views/frame/opaque_non_client_view.cc +++ b/chrome/browser/views/frame/opaque_non_client_view.cc @@ -6,6 +6,7 @@ #include "chrome/browser/views/frame/browser_view.h" #include "chrome/browser/views/tabs/tab_strip.h" +#include "chrome/common/gfx/chrome_canvas.h" #include "chrome/common/gfx/chrome_font.h" #include "chrome/common/gfx/path.h" #include "chrome/common/l10n_util.h" diff --git a/chrome/browser/views/frame/opaque_non_client_view.h b/chrome/browser/views/frame/opaque_non_client_view.h index 8caf563..6160b9d 100644 --- a/chrome/browser/views/frame/opaque_non_client_view.h +++ b/chrome/browser/views/frame/opaque_non_client_view.h @@ -11,6 +11,7 @@ #include "chrome/views/button.h" class BrowserView; +class ChromeFont; class OpaqueFrame; class TabContents; class TabStrip; diff --git a/chrome/browser/views/fullscreen_exit_bubble.cc b/chrome/browser/views/fullscreen_exit_bubble.cc index 170763b..efc600a 100644 --- a/chrome/browser/views/fullscreen_exit_bubble.cc +++ b/chrome/browser/views/fullscreen_exit_bubble.cc @@ -5,13 +5,13 @@ #include "chrome/browser/views/fullscreen_exit_bubble.h" #include "chrome/app/chrome_dll_resource.h" +#include "chrome/common/gfx/chrome_canvas.h" #include "chrome/common/l10n_util.h" #include "chrome/common/l10n_util_win.h" #include "chrome/common/resource_bundle.h" #include "chrome/views/root_view.h" #include "grit/generated_resources.h" - // FullscreenExitView ---------------------------------------------------------- class FullscreenExitBubble::FullscreenExitView : public views::View { diff --git a/chrome/browser/views/infobars/infobars.cc b/chrome/browser/views/infobars/infobars.cc index 6b7342f..aa60a6b 100644 --- a/chrome/browser/views/infobars/infobars.cc +++ b/chrome/browser/views/infobars/infobars.cc @@ -7,6 +7,7 @@ #include "base/message_loop.h" #include "chrome/browser/views/event_utils.h" #include "chrome/browser/views/infobars/infobar_container.h" +#include "chrome/common/gfx/chrome_canvas.h" #include "chrome/common/l10n_util.h" #include "chrome/common/resource_bundle.h" #include "chrome/common/slide_animation.h" diff --git a/chrome/browser/views/options/cookies_view.cc b/chrome/browser/views/options/cookies_view.cc index 19825ef..e4380a1f5 100644 --- a/chrome/browser/views/options/cookies_view.cc +++ b/chrome/browser/views/options/cookies_view.cc @@ -10,6 +10,7 @@ #include "base/time_format.h" #include "chrome/browser/profile.h" #include "chrome/browser/views/standard_layout.h" +#include "chrome/common/gfx/chrome_canvas.h" #include "chrome/common/gfx/color_utils.h" #include "chrome/common/l10n_util.h" #include "chrome/common/resource_bundle.h" diff --git a/chrome/browser/views/sad_tab_view.h b/chrome/browser/views/sad_tab_view.h index 37d8d99..15e7afe 100644 --- a/chrome/browser/views/sad_tab_view.h +++ b/chrome/browser/views/sad_tab_view.h @@ -2,12 +2,14 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_VIEWS_SAD_TAB_H__ -#define CHROME_BROWSER_VIEWS_SAD_TAB_H__ +#ifndef CHROME_BROWSER_VIEWS_SAD_TAB_H_ +#define CHROME_BROWSER_VIEWS_SAD_TAB_H_ #include "chrome/common/gfx/chrome_font.h" #include "chrome/views/view.h" +class SkBitmap; + /////////////////////////////////////////////////////////////////////////////// // // SadTabView @@ -52,5 +54,4 @@ class SadTabView : public views::View { DISALLOW_EVIL_CONSTRUCTORS(SadTabView); }; -#endif // #ifndef CHROME_BROWSER_VIEWS_SAD_TAB_H__ - +#endif // #ifndef CHROME_BROWSER_VIEWS_SAD_TAB_H_ diff --git a/chrome/browser/views/star_toggle.h b/chrome/browser/views/star_toggle.h index 4ac8fa2..95f64db 100644 --- a/chrome/browser/views/star_toggle.h +++ b/chrome/browser/views/star_toggle.h @@ -8,6 +8,8 @@ #include "chrome/views/view.h" #include "chrome/views/event.h" +class SkBitmap; + //////////////////////////////////////////////////////////////////////////////// // // A view subclass to implement the star button. The star button notifies its diff --git a/chrome/browser/views/tab_icon_view.h b/chrome/browser/views/tab_icon_view.h index a644163..3a731fc 100644 --- a/chrome/browser/views/tab_icon_view.h +++ b/chrome/browser/views/tab_icon_view.h @@ -7,6 +7,7 @@ #include "chrome/views/view.h" +class SkBitmap; class TabContents; //////////////////////////////////////////////////////////////////////////////// diff --git a/chrome/browser/views/tabs/dragged_tab_controller.cc b/chrome/browser/views/tabs/dragged_tab_controller.cc index 806faeb..e5e7cad 100644 --- a/chrome/browser/views/tabs/dragged_tab_controller.cc +++ b/chrome/browser/views/tabs/dragged_tab_controller.cc @@ -17,6 +17,7 @@ #include "chrome/browser/views/tabs/tab_strip.h" #include "chrome/browser/tab_contents/web_contents.h" #include "chrome/common/animation.h" +#include "chrome/common/gfx/chrome_canvas.h" #include "chrome/common/notification_service.h" #include "chrome/views/event.h" #include "chrome/views/root_view.h" diff --git a/chrome/browser/views/toolbar_view.cc b/chrome/browser/views/toolbar_view.cc index 295c6ef..dd88eff 100644 --- a/chrome/browser/views/toolbar_view.cc +++ b/chrome/browser/views/toolbar_view.cc @@ -30,6 +30,7 @@ #include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/drag_drop_types.h" +#include "chrome/common/gfx/chrome_canvas.h" #include "chrome/common/l10n_util.h" #include "chrome/common/notification_service.h" #include "chrome/common/os_exchange_data.h" diff --git a/chrome/common/gfx/chrome_canvas.h b/chrome/common/gfx/chrome_canvas.h index a78d85c..d6cf77f 100644 --- a/chrome/common/gfx/chrome_canvas.h +++ b/chrome/common/gfx/chrome_canvas.h @@ -147,6 +147,16 @@ class ChromeCanvas : public skia::PlatformCanvas { const SkColor& color, int x, int y, int w, int h, int flags); +#ifdef OS_WIN // Only implemented on Windows for now. + // Draws text with a 1-pixel halo around it of the given color. It allows + // ClearType to be drawn to an otherwise transparenct bitmap for drag images. + // Drag images have only 1-bit of transparency, so we don't do any fancy + // blurring. + void DrawStringWithHalo(const std::wstring& text, const ChromeFont& font, + const SkColor& text_color, const SkColor& halo_color, + int x, int y, int w, int h, int flags); +#endif + // Draws a dotted gray rectangle used for focus purposes. void DrawFocusRect(int x, int y, int width, int height); diff --git a/chrome/common/gfx/chrome_canvas_win.cc b/chrome/common/gfx/chrome_canvas_win.cc index 5e40ceb..376db65 100644 --- a/chrome/common/gfx/chrome_canvas_win.cc +++ b/chrome/common/gfx/chrome_canvas_win.cc @@ -195,3 +195,78 @@ void ChromeCanvas::DrawStringInt(const std::wstring& text, int x, int y, int w, int h, int flags) { DrawStringInt(text, font.hfont(), color, x, y, w, h, flags); } + +// Checks each pixel immediately adjacent to the given pixel in the bitmap. If +// any of them are not the halo color, returns true. This defines the halo of +// pixels that will appear around the text. Note that we have to check each +// pixel against both the halo color and transparent since DrawStringWithHalo +// will modify the bitmap as it goes, and clears pixels shouldn't count as +// changed. +static bool pixelShouldGetHalo(const SkBitmap& bitmap, int x, int y, + SkColor halo_color) { + if (x > 0 && + *bitmap.getAddr32(x - 1, y) != halo_color && + *bitmap.getAddr32(x - 1, y) != 0) + return true; // Touched pixel to the left. + if (x < bitmap.width() - 1 && + *bitmap.getAddr32(x + 1, y) != halo_color && + *bitmap.getAddr32(x + 1, y) != 0) + return true; // Touched pixel to the right. + if (y > 0 && + *bitmap.getAddr32(x, y - 1) != halo_color && + *bitmap.getAddr32(x, y - 1) != 0) + return true; // Touched pixel above. + if (y < bitmap.height() - 1 && + *bitmap.getAddr32(x, y + 1) != halo_color && + *bitmap.getAddr32(x, y + 1) != 0) + return true; // Touched pixel below. + return false; +} + +void ChromeCanvas::DrawStringWithHalo(const std::wstring& text, + const ChromeFont& font, + const SkColor& text_color, + const SkColor& halo_color_in, + int x, int y, int w, int h, + int flags) { + // Some callers will have semitransparent halo colors, which we don't handle + // (since the resulting image can have 1-bit transparency only). + SkColor halo_color = halo_color_in | 0xFF000000; + + // Create a temporary buffer filled with the halo color. It must leave room + // for the 1-pixel border around the text. + ChromeCanvas text_canvas(w + 2, h + 2, true); + SkPaint bkgnd_paint; + bkgnd_paint.setColor(halo_color); + text_canvas.FillRectInt(0, 0, w + 2, h + 2, bkgnd_paint); + + // Draw the text into the temporary buffer. This will have correct + // ClearType since the background color is the same as the halo color. + text_canvas.DrawStringInt(text, font, text_color, 1, 1, w, h, flags); + + // Windows will have cleared the alpha channel for the pixels it drew. Make it + // opaque. We have to do this first since pixelShouldGetHalo will check for + // 0 to see if a pixel has been modified to transparent, and black text that + // Windows draw will look transparent to it! + text_canvas.getTopPlatformDevice().makeOpaque(0, 0, w + 2, h + 2); + + uint32_t halo_premul = SkPreMultiplyColor(halo_color); + SkBitmap& text_bitmap = const_cast<SkBitmap&>( + text_canvas.getTopPlatformDevice().accessBitmap(true)); + for (int cur_y = 0; cur_y < h + 2; cur_y++) { + uint32_t* text_row = text_bitmap.getAddr32(0, cur_y); + for (int cur_x = 0; cur_x < w + 2; cur_x++) { + if (text_row[cur_x] == halo_premul) { + // This pixel was not touched by the text routines. See if it borders + // a touched pixel in any of the 4 directions (not diagonally). + if (!pixelShouldGetHalo(text_bitmap, cur_x, cur_y, halo_premul)) + text_row[cur_x] = 0; // Make transparent. + } else { + text_row[cur_x] |= 0xff << SK_A32_SHIFT; // Make opaque. + } + } + } + + // Draw the halo bitmap with blur. + drawBitmap(text_bitmap, SkIntToScalar(x - 1), SkIntToScalar(y - 1)); +} diff --git a/chrome/views/border.cc b/chrome/views/border.cc index 680c071..b454c47 100644 --- a/chrome/views/border.cc +++ b/chrome/views/border.cc @@ -5,6 +5,7 @@ #include "chrome/views/border.h" #include "base/logging.h" +#include "chrome/common/gfx/chrome_canvas.h" namespace views { diff --git a/chrome/views/border.h b/chrome/views/border.h index 2493717..ae6831c 100644 --- a/chrome/views/border.h +++ b/chrome/views/border.h @@ -2,14 +2,15 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_VIEWS_BORDER_H__ -#define CHROME_VIEWS_BORDER_H__ +#ifndef CHROME_VIEWS_BORDER_H_ +#define CHROME_VIEWS_BORDER_H_ -#include "chrome/common/gfx/chrome_canvas.h" #include "chrome/common/gfx/insets.h" #include "chrome/views/view.h" #include "SkColor.h" +class ChromeCanvas; + namespace views { class View; @@ -50,10 +51,9 @@ class Border { virtual void GetInsets(gfx::Insets* insets) const = 0; private: - DISALLOW_EVIL_CONSTRUCTORS(Border); + DISALLOW_COPY_AND_ASSIGN(Border); }; } // namespace views -#endif // CHROME_VIEWS_BORDER_H__ - +#endif // CHROME_VIEWS_BORDER_H_ diff --git a/chrome/views/chrome_menu.cc b/chrome/views/chrome_menu.cc index f226987..96b24dc 100644 --- a/chrome/views/chrome_menu.cc +++ b/chrome/views/chrome_menu.cc @@ -1479,10 +1479,20 @@ void MenuItemView::Paint(ChromeCanvas* canvas, bool for_drag) { ChromeFont& font = GetRootMenuItem()->font_; gfx::Rect text_bounds(label_start, top_margin, width, font.height()); text_bounds.set_x(MirroredLeftPointForRect(text_bounds)); - canvas->DrawStringInt(GetTitle(), font, fg_color, - text_bounds.x(), text_bounds.y(), text_bounds.width(), - text_bounds.height(), - GetRootMenuItem()->GetDrawStringFlags()); + if (for_drag) { + // With different themes, it's difficult to tell what the correct foreground + // and background colors are for the text to draw the correct halo. Instead, + // just draw black on white, which will look good in most cases. + canvas->DrawStringWithHalo(GetTitle(), font, 0x00000000, 0xFFFFFFFF, + text_bounds.x(), text_bounds.y(), + text_bounds.width(), text_bounds.height(), + GetRootMenuItem()->GetDrawStringFlags()); + } else { + canvas->DrawStringInt(GetTitle(), font, fg_color, + text_bounds.x(), text_bounds.y(), text_bounds.width(), + text_bounds.height(), + GetRootMenuItem()->GetDrawStringFlags()); + } if (icon_.width() > 0) { gfx::Rect icon_bounds(kItemLeftMargin, diff --git a/chrome/views/default_non_client_view.cc b/chrome/views/default_non_client_view.cc index cde277d..e3998a5 100644 --- a/chrome/views/default_non_client_view.cc +++ b/chrome/views/default_non_client_view.cc @@ -6,6 +6,7 @@ #include "base/win_util.h" #include "chrome/common/gfx/path.h" +#include "chrome/common/gfx/chrome_canvas.h" #include "chrome/common/gfx/chrome_font.h" #include "chrome/common/resource_bundle.h" #include "chrome/common/win_util.h" diff --git a/chrome/views/default_non_client_view.h b/chrome/views/default_non_client_view.h index a0a87e9..2c46fca 100644 --- a/chrome/views/default_non_client_view.h +++ b/chrome/views/default_non_client_view.h @@ -5,6 +5,7 @@ #ifndef CHROME_VIEWS_DEFAULT_NON_CLIENT_VIEW_H_ #define CHROME_VIEWS_DEFAULT_NON_CLIENT_VIEW_H_ +#include "base/basictypes.h" #include "chrome/views/button.h" #include "chrome/views/custom_frame_window.h" #include "chrome/views/non_client_view.h" @@ -16,6 +17,7 @@ class Path; class Point; } class ChromeCanvas; +class ChromeFont; namespace views { @@ -118,9 +120,9 @@ class DefaultNonClientView : public NonClientView, static WindowResources* inactive_resources_; static ChromeFont title_font_; - DISALLOW_EVIL_CONSTRUCTORS(DefaultNonClientView); + DISALLOW_COPY_AND_ASSIGN(DefaultNonClientView); }; } // namespace views -#endif // #ifndef CHROME_VIEWS_DEFAULT_NON_CLIENT_VIEW_H_ +#endif // CHROME_VIEWS_DEFAULT_NON_CLIENT_VIEW_H_ diff --git a/chrome/views/label_unittest.cc b/chrome/views/label_unittest.cc index 96b4d63..55154a3 100644 --- a/chrome/views/label_unittest.cc +++ b/chrome/views/label_unittest.cc @@ -3,6 +3,7 @@ // found in the LICENSE file. #include "base/string_util.h" +#include "chrome/common/gfx/chrome_canvas.h" #include "chrome/common/l10n_util.h" #include "chrome/views/border.h" #include "chrome/views/label.h" diff --git a/chrome/views/root_view_win.cc b/chrome/views/root_view_win.cc index 9b38e64f..8ea6444 100644 --- a/chrome/views/root_view_win.cc +++ b/chrome/views/root_view_win.cc @@ -6,6 +6,7 @@ #include "base/base_drag_source.h" #include "base/logging.h" +#include "chrome/common/gfx/chrome_canvas.h" #include "chrome/common/drag_drop_types.h" #include "chrome/views/root_view_drop_target.h" diff --git a/chrome/views/text_button.cc b/chrome/views/text_button.cc index f185745..ba4e3b2 100644 --- a/chrome/views/text_button.cc +++ b/chrome/views/text_button.cc @@ -5,6 +5,7 @@ #include "chrome/views/text_button.h" #include "chrome/common/gfx/chrome_canvas.h" +#include "chrome/common/l10n_util.h" #include "chrome/common/resource_bundle.h" #include "chrome/common/throb_animation.h" #include "chrome/common/win_util.h" @@ -260,22 +261,31 @@ void TextButton::Paint(ChromeCanvas* canvas, bool for_drag) { gfx::Rect text_bounds(text_x, text_y, text_width, text_size_.height()); text_bounds.set_x(MirroredLeftPointForRect(text_bounds)); - // Draw bevel highlight - canvas->DrawStringInt(text_, - font_, - kHighlightColor, - text_bounds.x() + 1, - text_bounds.y() + 1, - text_bounds.width(), - text_bounds.height()); - - canvas->DrawStringInt(text_, - font_, - color_, - text_bounds.x(), - text_bounds.y(), - text_bounds.width(), - text_bounds.height()); + if (for_drag) { + canvas->DrawStringWithHalo(text_, font_, color_, kHighlightColor, + text_bounds.x(), + text_bounds.y(), + text_bounds.width(), + text_bounds.height(), + l10n_util::DefaultCanvasTextAlignment()); + } else { + // Draw bevel highlight + canvas->DrawStringInt(text_, + font_, + kHighlightColor, + text_bounds.x() + 1, + text_bounds.y() + 1, + text_bounds.width(), + text_bounds.height()); + + canvas->DrawStringInt(text_, + font_, + color_, + text_bounds.x(), + text_bounds.y(), + text_bounds.width(), + text_bounds.height()); + } } if (icon_.width() > 0) { diff --git a/chrome/views/window.cc b/chrome/views/window.cc index 21a2f72..d4cb905 100644 --- a/chrome/views/window.cc +++ b/chrome/views/window.cc @@ -6,6 +6,7 @@ #include "base/win_util.h" #include "chrome/app/chrome_dll_resource.h" +#include "chrome/common/gfx/chrome_canvas.h" #include "chrome/common/gfx/chrome_font.h" #include "chrome/common/gfx/icon_util.h" #include "chrome/common/gfx/path.h" |