diff options
-rw-r--r-- | app/app_base.gypi | 2 | ||||
-rw-r--r-- | build/all.gyp | 12 | ||||
-rw-r--r-- | chrome/chrome.gyp | 4 | ||||
-rw-r--r-- | gfx/DEPS | 1 | ||||
-rw-r--r-- | gfx/blit.h | 45 | ||||
-rw-r--r-- | gfx/brush.h | 16 | ||||
-rw-r--r-- | gfx/canvas.h | 230 | ||||
-rw-r--r-- | gfx/canvas_direct2d.h | 104 | ||||
-rw-r--r-- | gfx/canvas_skia.h | 157 | ||||
-rw-r--r-- | gfx/canvas_skia_paint.h | 13 | ||||
-rw-r--r-- | gfx/color_utils.h | 72 | ||||
-rw-r--r-- | gfx/favicon_size.h | 26 | ||||
-rw-r--r-- | gfx/font.h | 105 | ||||
-rw-r--r-- | gfx/gdi_util.h | 30 | ||||
-rw-r--r-- | gfx/gfx_module.h | 26 | ||||
-rw-r--r-- | gfx/gfx_paths.h | 20 | ||||
-rw-r--r-- | gfx/gtk_native_view_id_manager.h | 133 | ||||
-rw-r--r-- | gfx/gtk_preserve_window.h | 56 | ||||
-rw-r--r-- | gfx/gtk_util.h | 76 | ||||
-rw-r--r-- | gfx/icon_util.h | 186 | ||||
-rw-r--r-- | gfx/insets.h | 86 | ||||
-rw-r--r-- | gfx/native_theme_linux.h | 231 | ||||
-rw-r--r-- | gfx/native_theme_win.h | 307 | ||||
-rw-r--r-- | gfx/native_widget_types.h | 168 | ||||
-rw-r--r-- | gfx/path.h | 49 | ||||
-rw-r--r-- | gfx/platform_font.h | 70 | ||||
-rw-r--r-- | gfx/platform_font_gtk.h | 99 | ||||
-rw-r--r-- | gfx/platform_font_mac.h | 49 | ||||
-rw-r--r-- | gfx/platform_font_win.h | 123 | ||||
-rw-r--r-- | gfx/point.h | 93 | ||||
-rw-r--r-- | gfx/rect.h | 169 | ||||
-rw-r--r-- | gfx/scoped_cg_context_state_mac.h | 23 | ||||
-rw-r--r-- | gfx/scoped_image.h | 139 | ||||
-rw-r--r-- | gfx/scrollbar_size.h | 10 | ||||
-rw-r--r-- | gfx/size.h | 74 | ||||
-rw-r--r-- | gfx/skbitmap_operations.h | 94 | ||||
-rw-r--r-- | gfx/skia_util.h | 31 | ||||
-rw-r--r-- | gfx/skia_utils_gtk.h | 15 | ||||
-rw-r--r-- | gfx/test_suite.h | 16 | ||||
-rw-r--r-- | gfx/win_util.h | 11 | ||||
-rw-r--r-- | gpu/gpu.gyp | 2 | ||||
-rw-r--r-- | media/tools/mfdecoder/README.chromium | 4 | ||||
-rw-r--r-- | remoting/remoting.gyp | 4 | ||||
-rw-r--r-- | tools/grit/resource_ids | 2 | ||||
-rw-r--r-- | ui/base/ui_base.gypi | 2 | ||||
-rw-r--r-- | ui/gfx/DEPS | 5 | ||||
-rw-r--r-- | ui/gfx/blit.cc (renamed from gfx/blit.cc) | 0 | ||||
-rw-r--r-- | ui/gfx/blit.h | 53 | ||||
-rw-r--r-- | ui/gfx/blit_unittest.cc (renamed from gfx/blit_unittest.cc) | 0 | ||||
-rw-r--r-- | ui/gfx/brush.h | 24 | ||||
-rw-r--r-- | ui/gfx/canvas.cc (renamed from gfx/canvas.cc) | 0 | ||||
-rw-r--r-- | ui/gfx/canvas.h | 238 | ||||
-rw-r--r-- | ui/gfx/canvas_direct2d.cc (renamed from gfx/canvas_direct2d.cc) | 0 | ||||
-rw-r--r-- | ui/gfx/canvas_direct2d.h | 112 | ||||
-rw-r--r-- | ui/gfx/canvas_direct2d_unittest.cc (renamed from gfx/canvas_direct2d_unittest.cc) | 0 | ||||
-rw-r--r-- | ui/gfx/canvas_skia.cc (renamed from gfx/canvas_skia.cc) | 0 | ||||
-rw-r--r-- | ui/gfx/canvas_skia.h | 165 | ||||
-rw-r--r-- | ui/gfx/canvas_skia_linux.cc (renamed from gfx/canvas_skia_linux.cc) | 0 | ||||
-rw-r--r-- | ui/gfx/canvas_skia_mac.mm (renamed from gfx/canvas_skia_mac.mm) | 0 | ||||
-rw-r--r-- | ui/gfx/canvas_skia_paint.h | 21 | ||||
-rw-r--r-- | ui/gfx/canvas_skia_win.cc (renamed from gfx/canvas_skia_win.cc) | 0 | ||||
-rw-r--r-- | ui/gfx/codec/DEPS (renamed from gfx/codec/DEPS) | 0 | ||||
-rw-r--r-- | ui/gfx/codec/jpeg_codec.cc (renamed from gfx/codec/jpeg_codec.cc) | 0 | ||||
-rw-r--r-- | ui/gfx/codec/jpeg_codec.h | 68 | ||||
-rw-r--r-- | ui/gfx/codec/jpeg_codec_unittest.cc (renamed from gfx/codec/jpeg_codec_unittest.cc) | 0 | ||||
-rw-r--r-- | ui/gfx/codec/png_codec.cc (renamed from gfx/codec/png_codec.cc) | 0 | ||||
-rw-r--r-- | ui/gfx/codec/png_codec.h | 105 | ||||
-rw-r--r-- | ui/gfx/codec/png_codec_unittest.cc (renamed from gfx/codec/png_codec_unittest.cc) | 0 | ||||
-rw-r--r-- | ui/gfx/color_utils.cc (renamed from gfx/color_utils.cc) | 0 | ||||
-rw-r--r-- | ui/gfx/color_utils.h | 80 | ||||
-rw-r--r-- | ui/gfx/color_utils_unittest.cc (renamed from gfx/color_utils_unittest.cc) | 0 | ||||
-rw-r--r-- | ui/gfx/empty.cc (renamed from gfx/empty.cc) | 0 | ||||
-rw-r--r-- | ui/gfx/favicon_size.h | 34 | ||||
-rw-r--r-- | ui/gfx/font.cc (renamed from gfx/font.cc) | 0 | ||||
-rw-r--r-- | ui/gfx/font.h | 113 | ||||
-rw-r--r-- | ui/gfx/font_unittest.cc (renamed from gfx/font_unittest.cc) | 0 | ||||
-rw-r--r-- | ui/gfx/gdi_util.cc (renamed from gfx/gdi_util.cc) | 0 | ||||
-rw-r--r-- | ui/gfx/gdi_util.h | 38 | ||||
-rw-r--r-- | ui/gfx/gfx.gyp (renamed from gfx/gfx.gyp) | 42 | ||||
-rw-r--r-- | ui/gfx/gfx_module.cc (renamed from gfx/gfx_module.cc) | 0 | ||||
-rw-r--r-- | ui/gfx/gfx_module.h | 34 | ||||
-rw-r--r-- | ui/gfx/gfx_paths.cc (renamed from gfx/gfx_paths.cc) | 0 | ||||
-rw-r--r-- | ui/gfx/gfx_paths.h | 28 | ||||
-rw-r--r-- | ui/gfx/gfx_resources.grd (renamed from gfx/gfx_resources.grd) | 2 | ||||
-rw-r--r-- | ui/gfx/gtk_native_view_id_manager.cc (renamed from gfx/gtk_native_view_id_manager.cc) | 0 | ||||
-rw-r--r-- | ui/gfx/gtk_native_view_id_manager.h | 141 | ||||
-rw-r--r-- | ui/gfx/gtk_preserve_window.cc (renamed from gfx/gtk_preserve_window.cc) | 0 | ||||
-rw-r--r-- | ui/gfx/gtk_preserve_window.h | 64 | ||||
-rw-r--r-- | ui/gfx/gtk_util.cc (renamed from gfx/gtk_util.cc) | 0 | ||||
-rw-r--r-- | ui/gfx/gtk_util.h | 84 | ||||
-rw-r--r-- | ui/gfx/icon_util.cc (renamed from gfx/icon_util.cc) | 0 | ||||
-rw-r--r-- | ui/gfx/icon_util.h | 194 | ||||
-rw-r--r-- | ui/gfx/icon_util_unittest.cc (renamed from gfx/icon_util_unittest.cc) | 0 | ||||
-rw-r--r-- | ui/gfx/insets.cc (renamed from gfx/insets.cc) | 0 | ||||
-rw-r--r-- | ui/gfx/insets.h | 94 | ||||
-rw-r--r-- | ui/gfx/insets_unittest.cc (renamed from gfx/insets_unittest.cc) | 0 | ||||
-rw-r--r-- | ui/gfx/native_theme_linux.cc (renamed from gfx/native_theme_linux.cc) | 0 | ||||
-rw-r--r-- | ui/gfx/native_theme_linux.h | 238 | ||||
-rw-r--r-- | ui/gfx/native_theme_win.cc (renamed from gfx/native_theme_win.cc) | 0 | ||||
-rw-r--r-- | ui/gfx/native_theme_win.h | 321 | ||||
-rw-r--r-- | ui/gfx/native_theme_win_unittest.cc (renamed from gfx/native_theme_win_unittest.cc) | 0 | ||||
-rw-r--r-- | ui/gfx/native_widget_types.h | 176 | ||||
-rw-r--r-- | ui/gfx/native_widget_types_gtk.cc (renamed from gfx/native_widget_types_gtk.cc) | 0 | ||||
-rw-r--r-- | ui/gfx/path.cc (renamed from gfx/path.cc) | 0 | ||||
-rw-r--r-- | ui/gfx/path.h | 57 | ||||
-rw-r--r-- | ui/gfx/path_gtk.cc (renamed from gfx/path_gtk.cc) | 0 | ||||
-rw-r--r-- | ui/gfx/path_win.cc (renamed from gfx/path_win.cc) | 0 | ||||
-rw-r--r-- | ui/gfx/platform_font.h | 79 | ||||
-rw-r--r-- | ui/gfx/platform_font_gtk.cc (renamed from gfx/platform_font_gtk.cc) | 0 | ||||
-rw-r--r-- | ui/gfx/platform_font_gtk.h | 107 | ||||
-rw-r--r-- | ui/gfx/platform_font_mac.h | 57 | ||||
-rw-r--r-- | ui/gfx/platform_font_mac.mm (renamed from gfx/platform_font_mac.mm) | 0 | ||||
-rw-r--r-- | ui/gfx/platform_font_win.cc (renamed from gfx/platform_font_win.cc) | 0 | ||||
-rw-r--r-- | ui/gfx/platform_font_win.h | 131 | ||||
-rw-r--r-- | ui/gfx/point.cc (renamed from gfx/point.cc) | 0 | ||||
-rw-r--r-- | ui/gfx/point.h | 101 | ||||
-rw-r--r-- | ui/gfx/rect.cc (renamed from gfx/rect.cc) | 0 | ||||
-rw-r--r-- | ui/gfx/rect.h | 184 | ||||
-rw-r--r-- | ui/gfx/rect_unittest.cc (renamed from gfx/rect_unittest.cc) | 0 | ||||
-rw-r--r-- | ui/gfx/run_all_unittests.cc (renamed from gfx/run_all_unittests.cc) | 0 | ||||
-rw-r--r-- | ui/gfx/scoped_cg_context_state_mac.h | 30 | ||||
-rw-r--r-- | ui/gfx/scoped_image.h | 147 | ||||
-rw-r--r-- | ui/gfx/scoped_image_unittest.cc (renamed from gfx/scoped_image_unittest.cc) | 0 | ||||
-rw-r--r-- | ui/gfx/scrollbar_size.cc (renamed from gfx/scrollbar_size.cc) | 0 | ||||
-rw-r--r-- | ui/gfx/scrollbar_size.h | 18 | ||||
-rw-r--r-- | ui/gfx/size.cc (renamed from gfx/size.cc) | 0 | ||||
-rw-r--r-- | ui/gfx/size.h | 82 | ||||
-rw-r--r-- | ui/gfx/skbitmap_operations.cc (renamed from gfx/skbitmap_operations.cc) | 0 | ||||
-rw-r--r-- | ui/gfx/skbitmap_operations.h | 102 | ||||
-rw-r--r-- | ui/gfx/skbitmap_operations_unittest.cc (renamed from gfx/skbitmap_operations_unittest.cc) | 0 | ||||
-rw-r--r-- | ui/gfx/skia_util.cc (renamed from gfx/skia_util.cc) | 0 | ||||
-rw-r--r-- | ui/gfx/skia_util.h | 39 | ||||
-rw-r--r-- | ui/gfx/skia_utils_gtk.cc (renamed from gfx/skia_utils_gtk.cc) | 0 | ||||
-rw-r--r-- | ui/gfx/skia_utils_gtk.h | 23 | ||||
-rw-r--r-- | ui/gfx/test_suite.cc (renamed from gfx/test_suite.cc) | 0 | ||||
-rw-r--r-- | ui/gfx/test_suite.h | 24 | ||||
-rw-r--r-- | ui/gfx/win_util.cc (renamed from gfx/win_util.cc) | 0 | ||||
-rw-r--r-- | ui/gfx/win_util.h | 20 | ||||
-rw-r--r-- | webkit/support/webkit_support.gypi | 2 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_shell.gypi | 4 |
140 files changed, 3746 insertions, 3120 deletions
diff --git a/app/app_base.gypi b/app/app_base.gypi index 2f0e6d0..944f833 100644 --- a/app/app_base.gypi +++ b/app/app_base.gypi @@ -65,7 +65,7 @@ 'app_strings', '../base/base.gyp:base', '../base/base.gyp:base_i18n', - '../gfx/gfx.gyp:gfx', + '../ui/gfx/gfx.gyp:gfx', '../net/net.gyp:net', '../skia/skia.gyp:skia', '../third_party/icu/icu.gyp:icui18n', diff --git a/build/all.gyp b/build/all.gyp index 2206dca..ce18cdf 100644 --- a/build/all.gyp +++ b/build/all.gyp @@ -13,7 +13,7 @@ '../base/base.gyp:*', '../chrome/browser/sync/tools/sync_tools.gyp:*', '../chrome/chrome.gyp:*', - '../gfx/gfx.gyp:*', + '../ui/gfx/gfx.gyp:*', '../gpu/gpu.gyp:*', '../gpu/demos/demos.gyp:*', '../ipc/ipc.gyp:*', @@ -157,7 +157,7 @@ '../chrome/chrome.gyp:sync_unit_tests', '../chrome/chrome.gyp:ui_tests', '../chrome/chrome.gyp:unit_tests', - '../gfx/gfx.gyp:gfx_unittests', + '../ui/gfx/gfx.gyp:gfx_unittests', '../gpu/gpu.gyp:gpu_unittests', '../ipc/ipc.gyp:ipc_tests', '../jingle/jingle.gyp:notifier_unit_tests', @@ -248,7 +248,7 @@ '../chrome/chrome.gyp:sync_unit_tests', '../chrome/chrome.gyp:ui_tests', '../chrome/chrome.gyp:unit_tests', - '../gfx/gfx.gyp:gfx_unittests', + '../ui/gfx/gfx.gyp:gfx_unittests', '../gpu/gpu.gyp:gpu_unittests', '../ipc/ipc.gyp:ipc_tests', '../jingle/jingle.gyp:notifier_unit_tests', @@ -278,7 +278,7 @@ '../chrome/chrome.gyp:ui_tests', '../chrome/chrome.gyp:unit_tests', '../chrome/chrome.gyp:url_fetch_test', - '../gfx/gfx.gyp:gfx_unittests', + '../ui/gfx/gfx.gyp:gfx_unittests', '../gpu/gpu.gyp:gpu_unittests', '../ipc/ipc.gyp:ipc_tests', '../jingle/jingle.gyp:notifier_unit_tests', @@ -363,7 +363,7 @@ '../chrome_frame/chrome_frame.gyp:chrome_frame_unittests', '../chrome_frame/chrome_frame.gyp:npchrome_frame', '../courgette/courgette.gyp:courgette_unittests', - '../gfx/gfx.gyp:gfx_unittests', + '../ui/gfx/gfx.gyp:gfx_unittests', '../gpu/gpu.gyp:gpu_unittests', '../ipc/ipc.gyp:ipc_tests', '../jingle/jingle.gyp:notifier_unit_tests', @@ -463,7 +463,7 @@ '../chrome/chrome.gyp:ui_tests', '../chrome/chrome.gyp:unit_tests', '../chrome/chrome.gyp:url_fetch_test', - '../gfx/gfx.gyp:gfx_unittests', + '../ui/gfx/gfx.gyp:gfx_unittests', '../ipc/ipc.gyp:ipc_tests', '../jingle/jingle.gyp:notifier_unit_tests', '../media/media.gyp:ffmpeg_tests', diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index 0f1db96..63c9480 100644 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -1616,7 +1616,7 @@ '../app/app.gyp:*', '../base/base.gyp:*', '../chrome_frame/chrome_frame.gyp:*', - '../gfx/gfx.gyp:*', + '../ui/gfx/gfx.gyp:*', '../ipc/ipc.gyp:*', '../media/media.gyp:*', '../net/net.gyp:*', @@ -1849,7 +1849,7 @@ '<(grit_out_dir)/renderer_resources.pak', '<(grit_out_dir)/theme_resources.pak', '<(SHARED_INTERMEDIATE_DIR)/app/app_resources/app_resources.pak', - '<(SHARED_INTERMEDIATE_DIR)/gfx/gfx_resources.pak', + '<(SHARED_INTERMEDIATE_DIR)/ui/gfx/gfx_resources.pak', '<(SHARED_INTERMEDIATE_DIR)/net/net_resources.pak', '<(SHARED_INTERMEDIATE_DIR)/webkit/webkit_chromium_resources.pak', '<(SHARED_INTERMEDIATE_DIR)/webkit/webkit_resources.pak', @@ -2,4 +2,5 @@ include_rules = [ "+base", "+grit/gfx_resources.h", "+skia", + "+ui/gfx", ] @@ -6,48 +6,7 @@ #define GFX_BLIT_H_ #pragma once -#include "gfx/native_widget_types.h" - -namespace skia { -class PlatformCanvas; -} // namespace skia - -namespace gfx { - -class Point; -class Rect; - -// Blits a rectangle from the source context into the destination context. -void BlitContextToContext(NativeDrawingContext dst_context, - const Rect& dst_rect, - NativeDrawingContext src_context, - const Point& src_origin); - -// Blits a rectangle from the source context into the destination canvas. -void BlitContextToCanvas(skia::PlatformCanvas *dst_canvas, - const Rect& dst_rect, - NativeDrawingContext src_context, - const Point& src_origin); - -// Blits a rectangle from the source canvas into the destination context. -void BlitCanvasToContext(NativeDrawingContext dst_context, - const Rect& dst_rect, - skia::PlatformCanvas *src_canvas, - const Point& src_origin); - -// Blits a rectangle from the source canvas into the destination canvas. -void BlitCanvasToCanvas(skia::PlatformCanvas *dst_canvas, - const Rect& dst_rect, - skia::PlatformCanvas *src_canvas, - const Point& src_origin); - -// Scrolls the given subset of the given canvas by the given amount. -// The canvas should not have a clip or a transform applied, since platforms -// may implement those operations differently. -void ScrollCanvas(skia::PlatformCanvas* canvas, - const Rect& clip, - const Point& amount); - -} // namespace gfx +#include "ui/gfx/blit.h" +// TODO(sail): remove this file once all includes have been updated. #endif // GFX_BLIT_H_ diff --git a/gfx/brush.h b/gfx/brush.h index 125ee3c..de48204 100644 --- a/gfx/brush.h +++ b/gfx/brush.h @@ -6,19 +6,7 @@ #define GFX_BRUSH_H_ #pragma once -namespace gfx { - -// An object that encapsulates a platform native brush. -// Subclasses handle memory management of the underlying native brush. -class Brush { - public: - Brush() {} - virtual ~Brush() {} - - private: - DISALLOW_COPY_AND_ASSIGN(Brush); -}; - -} // namespace gfx +#include "ui/gfx/brush.h" +// TODO(sail): remove this file once all includes have been updated. #endif // GFX_BRUSH_H_ diff --git a/gfx/canvas.h b/gfx/canvas.h index 17a9586..62cc77e 100644 --- a/gfx/canvas.h +++ b/gfx/canvas.h @@ -6,233 +6,7 @@ #define GFX_CANVAS_H_ #pragma once -#include <string> - -#include "base/string16.h" -#include "gfx/native_widget_types.h" -// TODO(beng): remove this include when we no longer depend on SkTypes. -#include "skia/ext/platform_canvas.h" - -namespace gfx { - -class Brush; -class CanvasSkia; -class Font; -class Point; -class Rect; - -// TODO(beng): documentation. -class Canvas { - public: - // Specifies the alignment for text rendered with the DrawStringInt method. - enum { - TEXT_ALIGN_LEFT = 1, - TEXT_ALIGN_CENTER = 2, - TEXT_ALIGN_RIGHT = 4, - TEXT_VALIGN_TOP = 8, - TEXT_VALIGN_MIDDLE = 16, - TEXT_VALIGN_BOTTOM = 32, - - // Specifies the text consists of multiple lines. - MULTI_LINE = 64, - - // By default DrawStringInt does not process the prefix ('&') character - // specially. That is, the string "&foo" is rendered as "&foo". When - // rendering text from a resource that uses the prefix character for - // mnemonics, the prefix should be processed and can be rendered as an - // underline (SHOW_PREFIX), or not rendered at all (HIDE_PREFIX). - SHOW_PREFIX = 128, - HIDE_PREFIX = 256, - - // Prevent ellipsizing - NO_ELLIPSIS = 512, - - // Specifies if words can be split by new lines. - // This only works with MULTI_LINE. - CHARACTER_BREAK = 1024, - - // Instructs DrawStringInt() to render the text using RTL directionality. - // In most cases, passing this flag is not necessary because information - // about the text directionality is going to be embedded within the string - // in the form of special Unicode characters. However, we don't insert - // directionality characters into strings if the locale is LTR because some - // platforms (for example, an English Windows XP with no RTL fonts - // installed) don't support these characters. Thus, this flag should be - // used to render text using RTL directionality when the locale is LTR. - FORCE_RTL_DIRECTIONALITY = 2048, - }; - - virtual ~Canvas() {} - - // Creates an empty canvas. Must be initialized before it can be used. - static Canvas* CreateCanvas(); - - // Creates a canvas with the specified size. - static Canvas* CreateCanvas(int width, int height, bool is_opaque); - - // Saves a copy of the drawing state onto a stack, operating on this copy - // until a balanced call to Restore() is made. - virtual void Save() = 0; - - // As with Save(), except draws to a layer that is blended with the canvas - // at the specified alpha once Restore() is called. - // |layer_bounds| are the bounds of the layer relative to the current - // transform. - virtual void SaveLayerAlpha(uint8 alpha) = 0; - virtual void SaveLayerAlpha(uint8 alpha, const gfx::Rect& layer_bounds) = 0; - - // Restores the drawing state after a call to Save*(). It is an error to - // call Restore() more times than Save*(). - virtual void Restore() = 0; - - // Wrapper function that takes integer arguments. - // Returns true if the clip is non-empty. - // See clipRect for specifics. - virtual bool ClipRectInt(int x, int y, int w, int h) = 0; - - // Wrapper function that takes integer arguments. - // See translate() for specifics. - virtual void TranslateInt(int x, int y) = 0; - - // Wrapper function that takes integer arguments. - // See scale() for specifics. - virtual void ScaleInt(int x, int y) = 0; - - // Fills the specified region with the specified color using a transfer - // mode of SkXfermode::kSrcOver_Mode. - virtual void FillRectInt(const SkColor& color, - int x, int y, int w, int h) = 0; - - // Fills the specified region with the specified color and mode - virtual void FillRectInt(const SkColor& color, - int x, int y, int w, int h, - SkXfermode::Mode mode) = 0; - - // Fills the specified region with the specified brush. - virtual void FillRectInt(const gfx::Brush* brush, - int x, int y, int w, int h) = 0; - - // Draws a single pixel rect in the specified region with the specified - // color, using a transfer mode of SkXfermode::kSrcOver_Mode. - // - // NOTE: if you need a single pixel line, use DrawLineInt. - virtual void DrawRectInt(const SkColor& color, - int x, int y, int w, int h) = 0; - - // Draws a single pixel rect in the specified region with the specified - // color and transfer mode. - // - // NOTE: if you need a single pixel line, use DrawLineInt. - virtual void DrawRectInt(const SkColor& color, - int x, int y, int w, int h, - SkXfermode::Mode mode) = 0; - - // Draws the given rectangle with the given paint's parameters. - virtual void DrawRectInt(int x, int y, int w, int h, - const SkPaint& paint) = 0; - - // Draws a single pixel line with the specified color. - virtual void DrawLineInt(const SkColor& color, - int x1, int y1, - int x2, int y2) = 0; - - // Draws a bitmap with the origin at the specified location. The upper left - // corner of the bitmap is rendered at the specified location. - virtual void DrawBitmapInt(const SkBitmap& bitmap, int x, int y) = 0; - - // Draws a bitmap with the origin at the specified location, using the - // specified paint. The upper left corner of the bitmap is rendered at the - // specified location. - virtual void DrawBitmapInt(const SkBitmap& bitmap, - int x, int y, - const SkPaint& paint) = 0; - - // Draws a portion of a bitmap in the specified location. The src parameters - // correspond to the region of the bitmap to draw in the region defined - // by the dest coordinates. - // - // If the width or height of the source differs from that of the destination, - // the bitmap will be scaled. When scaling down, it is highly recommended - // that you call buildMipMap(false) on your bitmap to ensure that it has - // a mipmap, which will result in much higher-quality output. Set |filter| - // to use filtering for bitmaps, otherwise the nearest-neighbor algorithm - // is used for resampling. - // - // An optional custom SkPaint can be provided. - virtual void DrawBitmapInt(const SkBitmap& bitmap, - int src_x, int src_y, int src_w, int src_h, - int dest_x, int dest_y, int dest_w, int dest_h, - bool filter) = 0; - virtual void DrawBitmapInt(const SkBitmap& bitmap, - int src_x, int src_y, int src_w, int src_h, - int dest_x, int dest_y, int dest_w, int dest_h, - bool filter, - const SkPaint& paint) = 0; - - // Draws text with the specified color, font and location. The text is - // aligned to the left, vertically centered, clipped to the region. If the - // text is too big, it is truncated and '...' is added to the end. - virtual void DrawStringInt(const string16& text, const - gfx::Font& font, - const SkColor& color, - int x, int y, int w, int h) = 0; - virtual void DrawStringInt(const string16& text, - const gfx::Font& font, - const SkColor& color, - const gfx::Rect& display_rect) = 0; - - // Draws text with the specified color, font and location. The last argument - // specifies flags for how the text should be rendered. It can be one of - // TEXT_ALIGN_CENTER, TEXT_ALIGN_RIGHT or TEXT_ALIGN_LEFT. - virtual void DrawStringInt(const string16& text, - const gfx::Font& font, - const SkColor& color, - int x, int y, int w, int h, - int flags) = 0; - - // Draws a dotted gray rectangle used for focus purposes. - virtual void DrawFocusRect(int x, int y, int width, int height) = 0; - - // Tiles the image in the specified region. - virtual void TileImageInt(const SkBitmap& bitmap, - int x, int y, int w, int h) = 0; - virtual void TileImageInt(const SkBitmap& bitmap, - int src_x, int src_y, - int dest_x, int dest_y, int w, int h) = 0; - - // Returns a native drawing context for platform specific drawing routines to - // use. Must be balanced by a call to EndPlatformPaint(). - virtual gfx::NativeDrawingContext BeginPlatformPaint() = 0; - - // Signifies the end of platform drawing using the native drawing context - // returned by BeginPlatformPaint(). - virtual void EndPlatformPaint() = 0; - - // TODO(beng): remove this once we don't need to use any skia-specific methods - // through this interface. - // A quick and dirty way to obtain the underlying SkCanvas. - virtual CanvasSkia* AsCanvasSkia(); - virtual const CanvasSkia* AsCanvasSkia() const; -}; - -class CanvasPaint { - public: - virtual ~CanvasPaint() {} - - // Creates a canvas that paints to |view| when it is destroyed. The canvas is - // sized to the client area of |view|. - static CanvasPaint* CreateCanvasPaint(gfx::NativeView view); - - // Returns true if the canvas has an invalid rect that needs to be repainted. - virtual bool IsValid() const = 0; - - // Returns the rectangle that is invalid. - virtual gfx::Rect GetInvalidRect() const = 0; - - // Returns the underlying Canvas. - virtual Canvas* AsCanvas() = 0; -}; - -} // namespace gfx; +#include "ui/gfx/canvas.h" +// TODO(sail): remove this file once all includes have been updated. #endif // GFX_CANVAS_H_ diff --git a/gfx/canvas_direct2d.h b/gfx/canvas_direct2d.h index 740a24d..4a46a396 100644 --- a/gfx/canvas_direct2d.h +++ b/gfx/canvas_direct2d.h @@ -6,107 +6,7 @@ #define GFX_CANVAS_DIRECT2D_H_ #pragma once -#include <d2d1.h> - -#include <stack> - -#include "base/scoped_comptr_win.h" -#include "gfx/canvas.h" - -namespace gfx { - -class CanvasDirect2D : public Canvas { - public: - // Creates an empty Canvas. - explicit CanvasDirect2D(ID2D1RenderTarget* rt); - virtual ~CanvasDirect2D(); - - // Retrieves the application's D2D1 Factory. - static ID2D1Factory* GetD2D1Factory(); - - // Overridden from Canvas: - virtual void Save(); - virtual void SaveLayerAlpha(uint8 alpha); - virtual void SaveLayerAlpha(uint8 alpha, const gfx::Rect& layer_bounds); - virtual void Restore(); - virtual bool ClipRectInt(int x, int y, int w, int h); - virtual void TranslateInt(int x, int y); - virtual void ScaleInt(int x, int y); - virtual void FillRectInt(const SkColor& color, int x, int y, int w, int h); - virtual void FillRectInt(const SkColor& color, int x, int y, int w, int h, - SkXfermode::Mode mode); - virtual void FillRectInt(const gfx::Brush* brush, int x, int y, int w, int h); - virtual void DrawRectInt(const SkColor& color, int x, int y, int w, int h); - virtual void DrawRectInt(const SkColor& color, - int x, int y, int w, int h, - SkXfermode::Mode mode); - virtual void DrawRectInt(int x, int y, int w, int h, const SkPaint& paint); - virtual void DrawLineInt(const SkColor& color, - int x1, int y1, - int x2, int y2); - virtual void DrawBitmapInt(const SkBitmap& bitmap, int x, int y); - virtual void DrawBitmapInt(const SkBitmap& bitmap, - int x, int y, - const SkPaint& paint); - virtual void DrawBitmapInt(const SkBitmap& bitmap, - int src_x, int src_y, int src_w, int src_h, - int dest_x, int dest_y, int dest_w, int dest_h, - bool filter); - virtual void DrawBitmapInt(const SkBitmap& bitmap, - int src_x, int src_y, int src_w, int src_h, - int dest_x, int dest_y, int dest_w, int dest_h, - bool filter, - const SkPaint& paint); - virtual void DrawStringInt(const string16& text, - const gfx::Font& font, - const SkColor& color, - int x, int y, int w, int h); - virtual void DrawStringInt(const string16& text, - const gfx::Font& font, - const SkColor& color, - const gfx::Rect& display_rect); - virtual void DrawStringInt(const string16& text, - const gfx::Font& font, - const SkColor& color, - int x, int y, int w, int h, - int flags); - virtual void DrawFocusRect(int x, int y, int width, int height); - virtual void TileImageInt(const SkBitmap& bitmap, int x, int y, int w, int h); - virtual void TileImageInt(const SkBitmap& bitmap, - int src_x, int src_y, - int dest_x, int dest_y, int w, int h); - virtual gfx::NativeDrawingContext BeginPlatformPaint(); - virtual void EndPlatformPaint(); - virtual CanvasSkia* AsCanvasSkia(); - virtual const CanvasSkia* AsCanvasSkia() const; - - private: - void SaveInternal(ID2D1Layer* layer); - - ID2D1RenderTarget* rt_; - ScopedComPtr<ID2D1GdiInteropRenderTarget> interop_rt_; - ScopedComPtr<ID2D1DrawingStateBlock> drawing_state_block_; - static ID2D1Factory* d2d1_factory_; - - // Every time Save* is called, a RenderState object is pushed onto the - // RenderState stack. - struct RenderState { - explicit RenderState(ID2D1Layer* layer) : layer(layer), clip_count(0) {} - RenderState() : layer(NULL), clip_count(0) {} - - // A D2D layer associated with this state, or NULL if there is no layer. - // The layer is created and owned by the Canvas. - ID2D1Layer* layer; - // The number of clip operations performed. This is used to balance calls to - // PushAxisAlignedClip with calls to PopAxisAlignedClip when Restore() is - // called. - int clip_count; - }; - std::stack<RenderState> state_; - - DISALLOW_COPY_AND_ASSIGN(CanvasDirect2D); -}; - -} // namespace gfx; +#include "ui/gfx/canvas_direct2d.h" +// TODO(sail): remove this file once all includes have been updated. #endif // GFX_CANVAS_DIRECT2D_H_ diff --git a/gfx/canvas_skia.h b/gfx/canvas_skia.h index b8b0aa9..d967eab 100644 --- a/gfx/canvas_skia.h +++ b/gfx/canvas_skia.h @@ -6,160 +6,7 @@ #define GFX_CANVAS_SKIA_H_ #pragma once -#include "base/basictypes.h" -#include "base/string16.h" -#include "gfx/canvas.h" -#include "skia/ext/platform_canvas.h" - -#if defined(OS_POSIX) && !defined(OS_MACOSX) -typedef struct _GdkPixbuf GdkPixbuf; -#endif - -namespace gfx { - -class Canvas; - -// CanvasSkia is a SkCanvas subclass that provides a number of methods for -// common operations used throughout an application built using base/gfx and -// app/gfx. -// -// All methods that take integer arguments (as is used throughout views) -// end with Int. If you need to use methods provided by the superclass -// you'll need to do a conversion. In particular you'll need to use -// macro SkIntToScalar(xxx), or if converting from a scalar to an integer -// SkScalarRound. -// -// A handful of methods in this class are overloaded providing an additional -// argument of type SkXfermode::Mode. SkXfermode::Mode specifies how the -// source and destination colors are combined. Unless otherwise specified, -// the variant that does not take a SkXfermode::Mode uses a transfer mode -// of kSrcOver_Mode. -class CanvasSkia : public skia::PlatformCanvas, - public Canvas { - public: - // Creates an empty Canvas. Callers must use initialize before using the - // canvas. - CanvasSkia(); - - CanvasSkia(int width, int height, bool is_opaque); - - virtual ~CanvasSkia(); - - // Compute the size required to draw some text with the provided font. - // Attempts to fit the text with the provided width and height. Increases - // height and then width as needed to make the text fit. This method - // supports multiple lines. - static void SizeStringInt(const string16& text, - const gfx::Font& font, - int* width, int* height, - int flags); - - // Returns the default text alignment to be used when drawing text on a - // gfx::CanvasSkia based on the directionality of the system locale language. - // This function is used by gfx::Canvas::DrawStringInt when the text alignment - // is not specified. - // - // This function returns either gfx::Canvas::TEXT_ALIGN_LEFT or - // gfx::Canvas::TEXT_ALIGN_RIGHT. - static int DefaultCanvasTextAlignment(); - -#if defined(OS_POSIX) && !defined(OS_MACOSX) - // Draw the pixbuf in its natural size at (x, y). - void DrawGdkPixbuf(GdkPixbuf* pixbuf, int x, int y); -#endif - -#if defined(OS_WIN) || (defined(OS_POSIX) && !defined(OS_MACOSX)) - // Draws text with a 1-pixel halo around it of the given color. - // On Windows, 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. - // On Linux, text with halo is created by stroking it with 2px |halo_color| - // then filling it with |text_color|. - void DrawStringWithHalo(const string16& text, - const gfx::Font& font, - const SkColor& text_color, - const SkColor& halo_color, - int x, int y, int w, int h, - int flags); -#endif - - // Extracts a bitmap from the contents of this canvas. - SkBitmap ExtractBitmap() const; - - // Overridden from Canvas: - virtual void Save(); - virtual void SaveLayerAlpha(uint8 alpha); - virtual void SaveLayerAlpha(uint8 alpha, const gfx::Rect& layer_bounds); - virtual void Restore(); - virtual bool ClipRectInt(int x, int y, int w, int h); - virtual void TranslateInt(int x, int y); - virtual void ScaleInt(int x, int y); - virtual void FillRectInt(const SkColor& color, int x, int y, int w, int h); - virtual void FillRectInt(const SkColor& color, int x, int y, int w, int h, - SkXfermode::Mode mode); - virtual void FillRectInt(const gfx::Brush* brush, int x, int y, int w, int h); - virtual void DrawRectInt(const SkColor& color, int x, int y, int w, int h); - virtual void DrawRectInt(const SkColor& color, - int x, int y, int w, int h, - SkXfermode::Mode mode); - virtual void DrawRectInt(int x, int y, int w, int h, const SkPaint& paint); - virtual void DrawLineInt(const SkColor& color, - int x1, int y1, - int x2, int y2); - virtual void DrawBitmapInt(const SkBitmap& bitmap, int x, int y); - virtual void DrawBitmapInt(const SkBitmap& bitmap, - int x, int y, - const SkPaint& paint); - virtual void DrawBitmapInt(const SkBitmap& bitmap, - int src_x, int src_y, int src_w, int src_h, - int dest_x, int dest_y, int dest_w, int dest_h, - bool filter); - virtual void DrawBitmapInt(const SkBitmap& bitmap, - int src_x, int src_y, int src_w, int src_h, - int dest_x, int dest_y, int dest_w, int dest_h, - bool filter, - const SkPaint& paint); - virtual void DrawStringInt(const string16& text, - const gfx::Font& font, - const SkColor& color, - int x, int y, int w, int h); - virtual void DrawStringInt(const string16& text, - const gfx::Font& font, - const SkColor& color, - const gfx::Rect& display_rect); - virtual void DrawStringInt(const string16& text, - const gfx::Font& font, - const SkColor& color, - int x, int y, int w, int h, - int flags); - virtual void DrawFocusRect(int x, int y, int width, int height); - virtual void TileImageInt(const SkBitmap& bitmap, int x, int y, int w, int h); - virtual void TileImageInt(const SkBitmap& bitmap, - int src_x, int src_y, - int dest_x, int dest_y, int w, int h); - virtual gfx::NativeDrawingContext BeginPlatformPaint(); - virtual void EndPlatformPaint(); - virtual CanvasSkia* AsCanvasSkia(); - virtual const CanvasSkia* AsCanvasSkia() const; - - private: - // Test whether the provided rectangle intersects the current clip rect. - bool IntersectsClipRectInt(int x, int y, int w, int h); - -#if defined(OS_WIN) - // Draws text with the specified color, font and location. The text is - // aligned to the left, vertically centered, clipped to the region. If the - // text is too big, it is truncated and '...' is added to the end. - void DrawStringInt(const string16& text, - HFONT font, - const SkColor& color, - int x, int y, int w, int h, - int flags); -#endif - - DISALLOW_COPY_AND_ASSIGN(CanvasSkia); -}; - -} // namespace gfx; +#include "ui/gfx/canvas_skia.h" +// TODO(sail): remove this file once all includes have been updated. #endif // GFX_CANVAS_SKIA_H_ diff --git a/gfx/canvas_skia_paint.h b/gfx/canvas_skia_paint.h index 56c6d83..5d57184 100644 --- a/gfx/canvas_skia_paint.h +++ b/gfx/canvas_skia_paint.h @@ -6,16 +6,7 @@ #define GFX_CANVAS_SKIA_PAINT_H_ #pragma once -#include "gfx/canvas_skia.h" -#include "skia/ext/canvas_paint.h" - -// Define a gfx::CanvasSkiaPaint type that wraps our gfx::Canvas like the -// skia::PlatformCanvasPaint wraps PlatformCanvas. - -namespace gfx { - -typedef skia::CanvasPaintT<CanvasSkia> CanvasSkiaPaint; - -} // namespace gfx +#include "ui/gfx/canvas_skia_paint.h" +// TODO(sail): remove this file once all includes have been updated. #endif // GFX_CANVAS_SKIA_PAINT_H_ diff --git a/gfx/color_utils.h b/gfx/color_utils.h index b6eb2da..166a793 100644 --- a/gfx/color_utils.h +++ b/gfx/color_utils.h @@ -6,75 +6,7 @@ #define APP_GFX_COLOR_UTILS_H_ #pragma once -#include "third_party/skia/include/core/SkColor.h" - -class SkBitmap; - -namespace color_utils { - -// Represents an HSL color. -struct HSL { - double h; - double s; - double l; -}; - -// Calculated according to http://www.w3.org/TR/WCAG20/#relativeluminancedef -double RelativeLuminance(SkColor color); - -// Note: these transformations assume sRGB as the source color space -void SkColorToHSL(SkColor c, HSL* hsl); -SkColor HSLToSkColor(const HSL& hsl, SkAlpha alpha); - -// HSL-Shift an SkColor. The shift values are in the range of 0-1, with the -// option to specify -1 for 'no change'. The shift values are defined as: -// hsl_shift[0] (hue): The absolute hue value - 0 and 1 map -// to 0 and 360 on the hue color wheel (red). -// hsl_shift[1] (saturation): A saturation shift, with the -// following key values: -// 0 = remove all color. -// 0.5 = leave unchanged. -// 1 = fully saturate the image. -// hsl_shift[2] (lightness): A lightness shift, with the -// following key values: -// 0 = remove all lightness (make all pixels black). -// 0.5 = leave unchanged. -// 1 = full lightness (make all pixels white). -SkColor HSLShift(SkColor color, const HSL& shift); - -// Determine if a given alpha value is nearly completely transparent. -bool IsColorCloseToTransparent(SkAlpha alpha); - -// Determine if a color is near grey. -bool IsColorCloseToGrey(int r, int g, int b); - -// Gets a color representing a bitmap. The definition of "representing" is the -// average color in the bitmap. The color returned is modified to have the -// specified alpha. -SkColor GetAverageColorOfFavicon(SkBitmap* bitmap, SkAlpha alpha); - -// Builds a histogram based on the Y' of the Y'UV representation of -// this image. -void BuildLumaHistogram(SkBitmap* bitmap, int histogram[256]); - -// Returns a blend of the supplied colors, ranging from |background| (for -// |alpha| == 0) to |foreground| (for |alpha| == 255). The alpha channels of -// the supplied colors are also taken into account, so the returned color may -// be partially transparent. -SkColor AlphaBlend(SkColor foreground, SkColor background, SkAlpha alpha); - -// Given a foreground and background color, try to return a foreground color -// that is "readable" over the background color by luma-inverting the foreground -// color and then picking whichever foreground color has higher contrast against -// the background color. -// -// NOTE: This won't do anything but waste time if the supplied foreground color -// has a luma value close to the midpoint (0.5 in the HSL representation). -SkColor GetReadableColor(SkColor foreground, SkColor background); - -// Gets a Windows system color as a SkColor -SkColor GetSysSkColor(int which); - -} // namespace color_utils +#include "ui/gfx/color_utils.h" +// TODO(sail): remove this file once all includes have been updated. #endif // APP_GFX_COLOR_UTILS_H_ diff --git a/gfx/favicon_size.h b/gfx/favicon_size.h index 018d348..9d36608 100644 --- a/gfx/favicon_size.h +++ b/gfx/favicon_size.h @@ -6,29 +6,7 @@ #define APP_GFX_FAVICON_SIZE_H_ #pragma once -#include "base/compiler_specific.h" - -// Size (along each axis) of the favicon. -const int kFavIconSize = 16; - -// If the width or height is bigger than the favicon size, a new width/height -// is calculated and returned in width/height that maintains the aspect -// ratio of the supplied values. -static void calc_favicon_target_size(int* width, int* height) ALLOW_UNUSED; - -// static -void calc_favicon_target_size(int* width, int* height) { - if (*width > kFavIconSize || *height > kFavIconSize) { - // Too big, resize it maintaining the aspect ratio. - float aspect_ratio = static_cast<float>(*width) / - static_cast<float>(*height); - *height = kFavIconSize; - *width = static_cast<int>(aspect_ratio * *height); - if (*width > kFavIconSize) { - *width = kFavIconSize; - *height = static_cast<int>(*width / aspect_ratio); - } - } -} +#include "ui/gfx/favicon_size.h" +// TODO(sail): remove this file once all includes have been updated. #endif // APP_GFX_FAVICON_SIZE_H_ @@ -6,108 +6,7 @@ #define GFX_FONT_H_ #pragma once -#include <string> - -#include "base/ref_counted.h" -#include "base/string16.h" -#include "gfx/native_widget_types.h" - -namespace gfx { - -class PlatformFont; - -// Font provides a wrapper around an underlying font. Copy and assignment -// operators are explicitly allowed, and cheap. -class Font { - public: - // The following constants indicate the font style. - enum FontStyle { - NORMAL = 0, - BOLD = 1, - ITALIC = 2, - UNDERLINED = 4, - }; - - // Creates a font with the default name and style. - Font(); - - // Creates a font that is a clone of another font object. - Font(const Font& other); - gfx::Font& operator=(const Font& other); - - // Creates a font from the specified native font. - explicit Font(NativeFont native_font); - - // Construct a Font object with the specified PlatformFont object. The Font - // object takes ownership of the PlatformFont object. - explicit Font(PlatformFont* platform_font); - - // Creates a font with the specified name and size. - Font(const string16& font_name, int font_size); - - ~Font(); - - // Returns a new Font derived from the existing font. - // size_deta is the size to add to the current font. For example, a value - // of 5 results in a font 5 units bigger than this font. - Font DeriveFont(int size_delta) const; - - // Returns a new Font derived from the existing font. - // size_delta is the size to add to the current font. See the single - // argument version of this method for an example. - // The style parameter specifies the new style for the font, and is a - // bitmask of the values: BOLD, ITALIC and UNDERLINED. - Font DeriveFont(int size_delta, int style) const; - - // Returns the number of vertical pixels needed to display characters from - // the specified font. This may include some leading, i.e. height may be - // greater than just ascent + descent. Specifically, the Windows and Mac - // implementations include leading and the Linux one does not. This may - // need to be revisited in the future. - int GetHeight() const; - - // Returns the baseline, or ascent, of the font. - int GetBaseline() const; - - // Returns the average character width for the font. - int GetAverageCharacterWidth() const; - - // Returns the number of horizontal pixels needed to display the specified - // string. - int GetStringWidth(const string16& text) const; - - // Returns the expected number of horizontal pixels needed to display the - // specified length of characters. Call GetStringWidth() to retrieve the - // actual number. - int GetExpectedTextWidth(int length) const; - - // Returns the style of the font. - int GetStyle() const; - - // Returns the font name. - string16 GetFontName() const; - - // Returns the font size in pixels. - int GetFontSize() const; - - // Returns the native font handle. - // Lifetime lore: - // Windows: This handle is owned by the Font object, and should not be - // destroyed by the caller. - // Mac: Caller must release this object. - // Gtk: This handle is created on demand, and must be freed by calling - // pango_font_description_free() when the caller is done using it. - NativeFont GetNativeFont() const; - - // Raw access to the underlying platform font implementation. Can be - // static_cast to a known implementation type if needed. - PlatformFont* platform_font() const { return platform_font_.get(); } - - private: - // Wrapped platform font implementation. - scoped_refptr<PlatformFont> platform_font_; -}; - -} // namespace gfx +#include "ui/gfx/font.h" +// TODO(sail): remove this file once all includes have been updated. #endif // GFX_FONT_H_ diff --git a/gfx/gdi_util.h b/gfx/gdi_util.h index 3f37ed8..324dafc 100644 --- a/gfx/gdi_util.h +++ b/gfx/gdi_util.h @@ -6,33 +6,7 @@ #define APP_GFX_GDI_UTIL_H_ #pragma once -#include <vector> -#include <windows.h> - -#include "gfx/rect.h" - -namespace gfx { - -// Creates a BITMAPINFOHEADER structure given the bitmap's size. -void CreateBitmapHeader(int width, int height, BITMAPINFOHEADER* hdr); - -// Creates a BITMAPINFOHEADER structure given the bitmap's size and -// color depth in bits per pixel. -void CreateBitmapHeaderWithColorDepth(int width, int height, int color_depth, - BITMAPINFOHEADER* hdr); - -// Creates a BITMAPV4HEADER structure given the bitmap's size. You probably -// only need to use BMP V4 if you need transparency (alpha channel). This -// function sets the AlphaMask to 0xff000000. -void CreateBitmapV4Header(int width, int height, BITMAPV4HEADER* hdr); - -// Creates a monochrome bitmap header. -void CreateMonochromeBitmapHeader(int width, int height, BITMAPINFOHEADER* hdr); - -// Modify the given hrgn by subtracting the given rectangles. -void SubtractRectanglesFromRegion(HRGN hrgn, - const std::vector<gfx::Rect>& cutouts); - -} // namespace gfx +#include "ui/gfx/gdi_util.h" +// TODO(sail): remove this file once all includes have been updated. #endif // APP_GFX_GDI_UTIL_H_ diff --git a/gfx/gfx_module.h b/gfx/gfx_module.h index 91f8963..aa9510c 100644 --- a/gfx/gfx_module.h +++ b/gfx/gfx_module.h @@ -6,29 +6,7 @@ #define GFX_MODULE_H_ #pragma once -#include "base/basictypes.h" -#include "base/string_piece.h" - -namespace gfx { - -// Defines global initializers and associated methods for the gfx module. -// See net/base/net_module.h for more details. -class GfxModule { - public: - typedef base::StringPiece (*ResourceProvider)(int key); - - // Set the function to call when the gfx module needs resources - static void SetResourceProvider(ResourceProvider func); - - // Call the resource provider (if one exists) to get the specified resource. - // Returns an empty string if the resource does not exist or if there is no - // resource provider. - static base::StringPiece GetResource(int key); - - private: - DISALLOW_IMPLICIT_CONSTRUCTORS(GfxModule); -}; - -} // namespace gfx +#include "ui/gfx/gfx_module.h" +// TODO(sail): remove this file once all includes have been updated. #endif // GFX_MODULE_H_ diff --git a/gfx/gfx_paths.h b/gfx/gfx_paths.h index 596fba3..8ee96bf 100644 --- a/gfx/gfx_paths.h +++ b/gfx/gfx_paths.h @@ -6,23 +6,7 @@ #define GFX_GFX_PATHS_H_ #pragma once -// This file declares path keys for the app module. These can be used with -// the PathService to access various special directories and files. - -namespace gfx { - -enum { - PATH_START = 2000, - - // Valid only in development environment; TODO(darin): move these - DIR_TEST_DATA, // Directory where unit test data resides. - - PATH_END -}; - -// Call once to register the provider for the path keys defined above. -void RegisterPathProvider(); - -} // namespace gfx +#include "ui/gfx/gfx_paths.h" +// TODO(sail): remove this file once all includes have been updated. #endif // GFX_GFX_PATHS_H_ diff --git a/gfx/gtk_native_view_id_manager.h b/gfx/gtk_native_view_id_manager.h index 8772bc8..8fd601b 100644 --- a/gfx/gtk_native_view_id_manager.h +++ b/gfx/gtk_native_view_id_manager.h @@ -6,136 +6,7 @@ #define GFX_GTK_NATIVE_VIEW_ID_MANAGER_H_ #pragma once -#include <map> - -#include "base/singleton.h" -#include "base/synchronization/lock.h" -#include "gfx/native_widget_types.h" - -typedef unsigned long XID; -struct _GtkPreserveWindow; - -// NativeViewIds are the opaque values which the renderer holds as a reference -// to a window. These ids are often used in sync calls from the renderer and -// one cannot terminate sync calls on the UI thread as that can lead to -// deadlocks. -// -// Because of this, we have the BACKGROUND_X11 thread for these calls and this -// thread has a separate X connection in order to answer them. But one cannot -// use GTK on multiple threads, so the BACKGROUND_X11 thread deals only in Xlib -// calls and, thus, XIDs. -// -// So we could make NativeViewIds be the X id of the window. However, at the -// time when we need to tell the renderer about its NativeViewId, an XID isn't -// availible and it goes very much against the grain of the code to make it so. -// Also, we worry that GTK might choose to change the underlying X window id -// when, say, the widget is hidden or repacked. Finally, if we used XIDs then a -// compromised renderer could start asking questions about any X windows on the -// system. -// -// Thus, we have this object. It produces random NativeViewIds from GtkWidget -// pointers and observes the various signals from the widget for when an X -// window is created, destroyed etc. Thus it provides a thread safe mapping -// from NativeViewIds to the current XID for that widget. -class GtkNativeViewManager { - public: - // Returns the singleton instance. - static GtkNativeViewManager* GetInstance(); - - // Must be called from the UI thread: - // - // Return a NativeViewId for the given widget and attach to the various - // signals emitted by that widget. The NativeViewId is pseudo-randomly - // allocated so that a compromised renderer trying to guess values will fail - // with high probability. The NativeViewId will not be reused for the - // lifetime of the GtkWidget. - gfx::NativeViewId GetIdForWidget(gfx::NativeView widget); - - // May be called from any thread: - // - // xid: (output) the resulting X window ID, or 0 - // id: a value previously returned from GetIdForWidget - // returns: true if |id| is a valid id, false otherwise. - // - // If the widget referenced by |id| does not current have an X window id, - // |*xid| is set to 0. - bool GetXIDForId(XID* xid, gfx::NativeViewId id); - - // Must be called from the UI thread because we may need the associated - // widget to create a window. - // - // Keeping the XID permanent requires a bit of overhead, so it must - // be explicitly requested. - // - // xid: (output) the resulting X window - // id: a value previously returned from GetIdForWidget - // returns: true if |id| is a valid id, false otherwise. - bool GetPermanentXIDForId(XID* xid, gfx::NativeViewId id); - - // Must be called from the UI thread because we may need to access a - // GtkWidget or destroy a GdkWindow. - // - // If the widget associated with the XID is still alive, allow the widget - // to destroy the associated XID when it wants. Otherwise, destroy the - // GdkWindow associated with the XID. - void ReleasePermanentXID(XID xid); - - // These are actually private functions, but need to be called from statics. - void OnRealize(gfx::NativeView widget); - void OnUnrealize(gfx::NativeView widget); - void OnDestroy(gfx::NativeView widget); - - base::Lock& unrealize_lock() { return unrealize_lock_; } - - private: - // This object is a singleton: - GtkNativeViewManager(); - ~GtkNativeViewManager(); - friend struct DefaultSingletonTraits<GtkNativeViewManager>; - - struct NativeViewInfo { - NativeViewInfo() : widget(NULL), x_window_id(0) { - } - gfx::NativeView widget; - XID x_window_id; - }; - - gfx::NativeViewId GetWidgetId(gfx::NativeView id); - - // This lock can be used to block GTK from unrealizing windows. This is needed - // when the BACKGROUND_X11 thread is using a window obtained via GetXIDForId, - // and can't allow the X11 resource to be deleted. - base::Lock unrealize_lock_; - - // protects native_view_to_id_ and id_to_info_ - base::Lock lock_; - - // If asked for an id for the same widget twice, we want to return the same - // id. So this records the current mapping. - std::map<gfx::NativeView, gfx::NativeViewId> native_view_to_id_; - std::map<gfx::NativeViewId, NativeViewInfo> id_to_info_; - - struct PermanentXIDInfo { - PermanentXIDInfo() : widget(NULL), ref_count(0) { - } - _GtkPreserveWindow* widget; - int ref_count; - }; - - // Used to maintain the reference count for permanent XIDs - // (referenced by GetPermanentXIDForId and dereferenced by - // ReleasePermanentXID). Only those XIDs with a positive reference count - // will be in the table. - // - // In general, several GTK widgets may share the same X window. We assume - // that is not true of the widgets stored in this registry. - // - // An XID will map to NULL, if there is an outstanding reference but the - // widget was destroyed. In this case, the destruction of the X window - // is deferred to the dropping of all references. - std::map<XID, PermanentXIDInfo> perm_xid_to_info_; - - DISALLOW_COPY_AND_ASSIGN(GtkNativeViewManager); -}; +#include "ui/gfx/gtk_native_view_id_manager.h" +// TODO(sail): remove this file once all includes have been updated. #endif // GFX_GTK_NATIVE_VIEW_ID_MANAGER_H_ diff --git a/gfx/gtk_preserve_window.h b/gfx/gtk_preserve_window.h index 2bbd277..bf62d00 100644 --- a/gfx/gtk_preserve_window.h +++ b/gfx/gtk_preserve_window.h @@ -6,59 +6,7 @@ #define GFX_GTK_PRESERVE_WINDOW_H_ #pragma once -#include <gdk/gdk.h> -#include <gtk/gtk.h> - -// GtkFixed creates an X window when realized and destroys an X window -// when unrealized. GtkPreserveWindow allows overrides this -// behaviour. When preserve is set (via gtk_preserve_window_set_preserve), -// the X window is only destroyed when the widget is destroyed. - -G_BEGIN_DECLS - -#define GTK_TYPE_PRESERVE_WINDOW \ - (gtk_preserve_window_get_type()) -#define GTK_PRESERVE_WINDOW(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST((obj), GTK_TYPE_PERSERVE_WINDOW, \ - GtkPreserveWindow)) -#define GTK_PRESERVE_WINDOW_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST((klass), GTK_TYPE_PRESERVE_WINDOW, \ - GtkPreserveWindowClass)) -#define GTK_IS_PRESERVE_WINDOW(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE((obj), GTK_TYPE_PRESERVE_WINDOW)) -#define GTK_IS_PRESERVE_WINDOW_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE((klass), GTK_TYPE_PRESERVE_WINDOW)) -#define GTK_PRESERVE_WINDOW_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS((obj), GTK_TYPE_PRESERVE_WINDOW, \ - GtkPreserveWindowClass)) - -typedef struct _GtkPreserveWindow GtkPreserveWindow; -typedef struct _GtkPreserveWindowClass GtkPreserveWindowClass; - -struct _GtkPreserveWindow { - // Parent class. - GtkFixed fixed; -}; - -struct _GtkPreserveWindowClass { - GtkFixedClass parent_class; -}; - -GType gtk_preserve_window_get_type() G_GNUC_CONST; -GtkWidget* gtk_preserve_window_new(); - -// Whether or not we should preserve associated windows as the widget -// is realized or unrealized. -gboolean gtk_preserve_window_get_preserve(GtkPreserveWindow* widget); -void gtk_preserve_window_set_preserve(GtkPreserveWindow* widget, - gboolean value); - -// Whether or not someone else will gdk_window_resize the GdkWindow associated -// with this widget (needed by the GPU process to synchronize resizing -// with swapped between front and back buffer). -void gtk_preserve_window_delegate_resize(GtkPreserveWindow* widget, - gboolean delegate); - -G_END_DECLS +#include "ui/gfx/gtk_preserve_window.h" +// TODO(sail): remove this file once all includes have been updated. #endif // GFX_GTK_PRESERVE_WINDOW_H_ diff --git a/gfx/gtk_util.h b/gfx/gtk_util.h index 683b80c..d8d0b49 100644 --- a/gfx/gtk_util.h +++ b/gfx/gtk_util.h @@ -6,79 +6,7 @@ #define GFX_GTK_UTIL_H_ #pragma once -#include <glib-object.h> -#include <stdint.h> - -#include <string> -#include <vector> - -#include "base/scoped_ptr.h" - -typedef struct _GdkPixbuf GdkPixbuf; -typedef struct _GdkRegion GdkRegion; -typedef struct _GdkCursor GdkCursor; - -class CommandLine; -class SkBitmap; - -namespace gfx { - -class Rect; - -// Call gtk_init() using the argc and argv from command_line. -// gtk_init() wants an argc and argv that it can mutate; we provide those, -// but leave the original CommandLine unaltered. -void GtkInitFromCommandLine(const CommandLine& command_line); - -// Convert and copy a SkBitmap to a GdkPixbuf. NOTE: this uses BGRAToRGBA, so -// it is an expensive operation. The returned GdkPixbuf will have a refcount of -// 1, and the caller is responsible for unrefing it when done. -GdkPixbuf* GdkPixbufFromSkBitmap(const SkBitmap* bitmap); - -// Modify the given region by subtracting the given rectangles. -void SubtractRectanglesFromRegion(GdkRegion* region, - const std::vector<Rect>& cutouts); - -// Returns the resolution (DPI) used by pango. A negative values means the -// resolution hasn't been set. -double GetPangoResolution(); - -// Returns a static instance of a GdkCursor* object, sharable across the -// process. Caller must gdk_cursor_ref() it if they want to assume ownership. -GdkCursor* GetCursor(int type); - -// Change windows accelerator style to GTK style. (GTK uses _ for -// accelerators. Windows uses & with && as an escape for &.) -std::string ConvertAcceleratorsFromWindowsStyle(const std::string& label); - -// Removes the "&" accelerators from a Windows label. -std::string RemoveWindowsStyleAccelerators(const std::string& label); - -// Makes a copy of |pixels| with the ordering changed from BGRA to RGBA. -// The caller is responsible for free()ing the data. If |stride| is 0, it's -// assumed to be 4 * |width|. -uint8_t* BGRAToRGBA(const uint8_t* pixels, int width, int height, int stride); - -} // namespace gfx - -namespace { -// A helper class that will g_object_unref |p| when it goes out of scope. -// This never adds a ref, it only unrefs. -template <typename Type> -struct GObjectUnrefer { - void operator()(Type* ptr) const { - if (ptr) - g_object_unref(ptr); - } -}; -} // namespace - -// It's not legal C++ to have a templatized typedefs, so we wrap it in a -// struct. When using this, you need to include ::Type. E.g., -// ScopedGObject<GdkPixbufLoader>::Type loader(gdk_pixbuf_loader_new()); -template<class T> -struct ScopedGObject { - typedef scoped_ptr_malloc<T, GObjectUnrefer<T> > Type; -}; +#include "ui/gfx/gtk_util.h" +// TODO(sail): remove this file once all includes have been updated. #endif // GFX_GTK_UTIL_H_ diff --git a/gfx/icon_util.h b/gfx/icon_util.h index 9f07b8d..6b96190 100644 --- a/gfx/icon_util.h +++ b/gfx/icon_util.h @@ -6,189 +6,7 @@ #define GFX_ICON_UTIL_H_ #pragma once -#include <windows.h> -#include <string> -#include <vector> -#include "base/basictypes.h" - -namespace gfx { -class Size; -} -class FilePath; -class SkBitmap; - -/////////////////////////////////////////////////////////////////////////////// -// -// The IconUtil class contains helper functions for manipulating Windows icons. -// The class interface contains methods for converting an HICON handle into an -// SkBitmap object and vice versa. The class can also create a .ico file given -// a PNG image contained in an SkBitmap object. The following code snippet -// shows an example usage of IconUtil::CreateHICONFromSkBitmap(): -// -// SkBitmap bitmap; -// -// // Fill |bitmap| with valid data -// bitmap.setConfig(...); -// bitmap.allocPixels(); -// -// ... -// -// // Convert the bitmap into a Windows HICON -// HICON icon = IconUtil::CreateHICONFromSkBitmap(bitmap); -// if (icon == NULL) { -// // Handle error -// ... -// } -// -// // Use the icon with a WM_SETICON message -// ::SendMessage(hwnd, WM_SETICON, static_cast<WPARAM>(ICON_BIG), -// reinterpret_cast<LPARAM>(icon)); -// -// // Destroy the icon when we are done -// ::DestroyIcon(icon); -// -/////////////////////////////////////////////////////////////////////////////// -class IconUtil { - public: - // Given an SkBitmap object, the function converts the bitmap to a Windows - // icon and returns the corresponding HICON handle. If the function cannot - // convert the bitmap, NULL is returned. - // - // The client is responsible for destroying the icon when it is no longer - // needed by calling ::DestroyIcon(). - static HICON CreateHICONFromSkBitmap(const SkBitmap& bitmap); - - // Given a valid HICON handle representing an icon, this function converts - // the icon into an SkBitmap object containing an ARGB bitmap using the - // dimensions specified in |s|. |s| must specify valid dimensions (both - // width() an height() must be greater than zero). If the function cannot - // convert the icon to a bitmap (most probably due to an invalid parameter), - // the return value is NULL. - // - // The client owns the returned bitmap object and is responsible for deleting - // it when it is no longer needed. - static SkBitmap* CreateSkBitmapFromHICON(HICON icon, const gfx::Size& s); - - // Given an initialized SkBitmap object and a file name, this function - // creates a .ico file with the given name using the provided bitmap. The - // icon file is created with multiple icon images of varying predefined - // dimensions because Windows uses different image sizes when loading icons, - // depending on where the icon is drawn (ALT+TAB window, desktop shortcut, - // Quick Launch, etc.). |icon_file_name| needs to specify the full path for - // the desired .ico file. - // - // The function returns true on success and false otherwise. - static bool CreateIconFileFromSkBitmap(const SkBitmap& bitmap, - const FilePath& icon_path); - - private: - // The icon format is published in the MSDN but there is no definition of - // the icon file structures in any of the Windows header files so we need to - // define these structure within the class. We must make sure we use 2 byte - // packing so that the structures are layed out properly within the file. -#pragma pack(push) -#pragma pack(2) - - // ICONDIRENTRY contains meta data for an individual icon image within a - // .ico file. - struct ICONDIRENTRY { - BYTE bWidth; - BYTE bHeight; - BYTE bColorCount; - BYTE bReserved; - WORD wPlanes; - WORD wBitCount; - DWORD dwBytesInRes; - DWORD dwImageOffset; - }; - - // ICONDIR Contains information about all the icon images contained within a - // single .ico file. - struct ICONDIR { - WORD idReserved; - WORD idType; - WORD idCount; - ICONDIRENTRY idEntries[1]; - }; - - // Contains the actual icon image. - struct ICONIMAGE { - BITMAPINFOHEADER icHeader; - RGBQUAD icColors[1]; - BYTE icXOR[1]; - BYTE icAND[1]; - }; -#pragma pack(pop) - - // Used for indicating that the .ico contains an icon (rather than a cursor) - // image. This value is set in the |idType| field of the ICONDIR structure. - static const int kResourceTypeIcon = 1; - - // The dimensions of the icon images we insert into the .ico file. - static const int icon_dimensions_[]; - - // Returns true if any pixel in the given pixels buffer has an non-zero alpha. - static bool PixelsHaveAlpha(const uint32* pixels, size_t num_pixels); - - // A helper function that initializes a BITMAPV5HEADER structure with a set - // of values. - static void InitializeBitmapHeader(BITMAPV5HEADER* header, int width, - int height); - - // Given a single SkBitmap object and pointers to the corresponding icon - // structures within the icon data buffer, this function sets the image - // information (dimensions, color depth, etc.) in the icon structures and - // also copies the underlying icon image into the appropriate location. - // - // The function will set the data pointed to by |image_byte_count| with the - // number of image bytes written to the buffer. Note that the number of bytes - // includes only the image data written into the memory pointed to by - // |icon_image|. - static void SetSingleIconImageInformation(const SkBitmap& bitmap, - size_t index, - ICONDIR* icon_dir, - ICONIMAGE* icon_image, - size_t image_offset, - size_t* image_byte_count); - - // Copies the bits of an SkBitmap object into a buffer holding the bits of - // the corresponding image for an icon within the .ico file. - static void CopySkBitmapBitsIntoIconBuffer(const SkBitmap& bitmap, - unsigned char* buffer, - size_t buffer_size); - - // Given a single bitmap, this function creates a set of bitmaps with - // specific dimensions by resizing the given bitmap to the appropriate sizes. - static void CreateResizedBitmapSet(const SkBitmap& bitmap_to_resize, - std::vector<SkBitmap>* bitmaps); - - // Given a set of bitmaps with varying dimensions, this function computes - // the amount of memory needed in order to store the bitmaps as image icons - // in a .ico file. - static size_t ComputeIconFileBufferSize(const std::vector<SkBitmap>& set); - - // A helper function for computing various size components of a given bitmap. - // The different sizes can be used within the various .ico file structures. - // - // |xor_mask_size| - the size, in bytes, of the XOR mask in the ICONIMAGE - // structure. - // |and_mask_size| - the size, in bytes, of the AND mask in the ICONIMAGE - // structure. - // |bytes_in_resource| - the total number of bytes set in the ICONIMAGE - // structure. This value is equal to the sum of the - // bytes in the AND mask and the XOR mask plus the size - // of the BITMAPINFOHEADER structure. Note that since - // only 32bpp are handled by the IconUtil class, the - // icColors field in the ICONIMAGE structure is ignored - // and is not accounted for when computing the - // different size components. - static void ComputeBitmapSizeComponents(const SkBitmap& bitmap, - size_t* xor_mask_size, - size_t* bytes_in_resource); - - // Prevent clients from instantiating objects of that class by declaring the - // ctor/dtor as private. - DISALLOW_IMPLICIT_CONSTRUCTORS(IconUtil); -}; +#include "ui/gfx/icon_util.h" +// TODO(sail): remove this file once all includes have been updated. #endif // GFX_ICON_UTIL_H_ diff --git a/gfx/insets.h b/gfx/insets.h index ba6cb58..aa1191b 100644 --- a/gfx/insets.h +++ b/gfx/insets.h @@ -6,89 +6,7 @@ #define GFX_INSETS_H_ #pragma once -#include "build/build_config.h" - -#if defined(OS_POSIX) && !defined(OS_MACOSX) -#include <gtk/gtkstyle.h> -#endif - -#include <string> - -namespace gfx { - -// -// An insets represents the borders of a container (the space the container must -// leave at each of its edges). -// - -class Insets { - public: - Insets() : top_(0), left_(0), bottom_(0), right_(0) {} - Insets(int top, int left, int bottom, int right) - : top_(top), - left_(left), - bottom_(bottom), - right_(right) {} -#if defined(OS_POSIX) && !defined(OS_MACOSX) - explicit Insets(const GtkBorder& border) - : top_(border.top), - left_(border.left), - bottom_(border.bottom), - right_(border.right) {} -#endif - - ~Insets() {} - - int top() const { return top_; } - int left() const { return left_; } - int bottom() const { return bottom_; } - int right() const { return right_; } - - // Returns the total width taken up by the insets, which is the sum of the - // left and right insets. - int width() const { return left_ + right_; } - - // Returns the total height taken up by the insets, which is the sum of the - // top and bottom insets. - int height() const { return top_ + bottom_; } - - // Returns true if the insets are empty. - bool empty() const { return width() == 0 && height() == 0; } - - void Set(int top, int left, int bottom, int right) { - top_ = top; - left_ = left; - bottom_ = bottom; - right_ = right; - } - - bool operator==(const Insets& insets) const { - return top_ == insets.top_ && left_ == insets.left_ && - bottom_ == insets.bottom_ && right_ == insets.right_; - } - - bool operator!=(const Insets& insets) const { - return !(*this == insets); - } - - Insets& operator+=(const Insets& insets) { - top_ += insets.top_; - left_ += insets.left_; - bottom_ += insets.bottom_; - right_ += insets.right_; - return *this; - } - - // Returns a string representation of the insets. - std::string ToString() const; - - private: - int top_; - int left_; - int bottom_; - int right_; -}; - -} // namespace gfx +#include "ui/gfx/insets.h" +// TODO(sail): remove this file once all includes have been updated. #endif // GFX_INSETS_H_ diff --git a/gfx/native_theme_linux.h b/gfx/native_theme_linux.h index 0837d2a..679c6b8 100644 --- a/gfx/native_theme_linux.h +++ b/gfx/native_theme_linux.h @@ -5,234 +5,7 @@ #ifndef GFX_NATIVE_THEME_LINUX_H_ #define GFX_NATIVE_THEME_LINUX_H_ -#include "base/basictypes.h" -#include "skia/ext/platform_canvas.h" - -namespace skia { -class PlatformCanvas; -} - -namespace gfx { -class Rect; -class Size; - -// Linux theming API. -class NativeThemeLinux { - public: - // The part to be painted / sized. - enum Part { - kScrollbarDownArrow, - kScrollbarLeftArrow, - kScrollbarRightArrow, - kScrollbarUpArrow, - kScrollbarHorizontalThumb, - kScrollbarVerticalThumb, - kScrollbarHorizontalTrack, - kScrollbarVerticalTrack, - kCheckbox, - kRadio, - kPushButton, - kTextField, - kMenuList, - kSliderTrack, - kSliderThumb, - kInnerSpinButton, - kProgressBar, - }; - - // The state of the part. - enum State { - kDisabled, - kHovered, - kNormal, - kPressed, - }; - - // Extra data needed to draw scrollbar track correctly. - struct ScrollbarTrackExtraParams { - int track_x; - int track_y; - int track_width; - int track_height; - }; - - struct ButtonExtraParams { - bool checked; - bool indeterminate; // Whether the button state is indeterminate. - bool is_default; // Whether the button is default button. - SkColor background_color; - }; - - struct TextFieldExtraParams { - bool is_text_area; - bool is_listbox; - SkColor background_color; - }; - - struct MenuListExtraParams { - int arrow_x; - int arrow_y; - SkColor background_color; - }; - - struct SliderExtraParams { - bool vertical; - bool in_drag; - }; - - struct InnerSpinButtonExtraParams { - bool spin_up; - bool read_only; - }; - - struct ProgressBarExtraParams { - bool determinate; - int value_rect_x; - int value_rect_y; - int value_rect_width; - int value_rect_height; - }; - - union ExtraParams { - ScrollbarTrackExtraParams scrollbar_track; - ButtonExtraParams button; - MenuListExtraParams menu_list; - SliderExtraParams slider; - TextFieldExtraParams text_field; - InnerSpinButtonExtraParams inner_spin; - ProgressBarExtraParams progress_bar; - }; - - // Gets our singleton instance. - static NativeThemeLinux* instance(); - - // Return the size of the part. - virtual gfx::Size GetPartSize(Part part) const; - // Paint the part to the canvas. - virtual void Paint(skia::PlatformCanvas* canvas, - Part part, - State state, - const gfx::Rect& rect, - const ExtraParams& extra); - // Supports theme specific colors. - void SetScrollbarColors(unsigned inactive_color, - unsigned active_color, - unsigned track_color) const; - - protected: - NativeThemeLinux(); - virtual ~NativeThemeLinux(); - - // Draw the arrow. Used by scrollbar and inner spin button. - virtual void PaintArrowButton( - skia::PlatformCanvas* gc, - const gfx::Rect& rect, - Part direction, - State state); - // Paint the scrollbar track. Done before the thumb so that it can contain - // alpha. - virtual void PaintScrollbarTrack(skia::PlatformCanvas* canvas, - Part part, - State state, - const ScrollbarTrackExtraParams& extra_params, - const gfx::Rect& rect); - // Draw the scrollbar thumb over the track. - virtual void PaintScrollbarThumb(skia::PlatformCanvas* canvas, - Part part, - State state, - const gfx::Rect& rect); - // Draw the checkbox. - virtual void PaintCheckbox(skia::PlatformCanvas* canvas, - State state, - const gfx::Rect& rect, - const ButtonExtraParams& button); - // Draw the radio. - virtual void PaintRadio(skia::PlatformCanvas* canvas, - State state, - const gfx::Rect& rect, - const ButtonExtraParams& button); - // Draw the push button. - virtual void PaintButton(skia::PlatformCanvas* canvas, - State state, - const gfx::Rect& rect, - const ButtonExtraParams& button); - // Draw the text field. - virtual void PaintTextField(skia::PlatformCanvas* canvas, - State state, - const gfx::Rect& rect, - const TextFieldExtraParams& text); - // Draw the menu list. - virtual void PaintMenuList(skia::PlatformCanvas* canvas, - State state, - const gfx::Rect& rect, - const MenuListExtraParams& menu_list); - // Draw the slider track. - virtual void PaintSliderTrack(skia::PlatformCanvas* canvas, - State state, - const gfx::Rect& rect, - const SliderExtraParams& slider); - // Draw the slider thumb. - virtual void PaintSliderThumb(skia::PlatformCanvas* canvas, - State state, - const gfx::Rect& rect, - const SliderExtraParams& slider); - // Draw the inner spin button. - virtual void PaintInnerSpinButton(skia::PlatformCanvas* canvas, - State state, - const gfx::Rect& rect, - const InnerSpinButtonExtraParams& spin_button); - // Draw the progress bar. - virtual void PaintProgressBar(skia::PlatformCanvas* canvas, - State state, - const gfx::Rect& rect, - const ProgressBarExtraParams& progress_bar); - - protected: - bool IntersectsClipRectInt(skia::PlatformCanvas* canvas, - int x, int y, int w, int h); - - void DrawBitmapInt(skia::PlatformCanvas* canvas, const SkBitmap& bitmap, - int src_x, int src_y, int src_w, int src_h, - int dest_x, int dest_y, int dest_w, int dest_h); - - void DrawTiledImage(SkCanvas* canvas, - const SkBitmap& bitmap, - int src_x, int src_y, - double tile_scale_x, double tile_scale_y, - int dest_x, int dest_y, int w, int h) const; - - SkColor SaturateAndBrighten(SkScalar* hsv, - SkScalar saturate_amount, - SkScalar brighten_amount) const; - - private: - void DrawVertLine(SkCanvas* canvas, - int x, - int y1, - int y2, - const SkPaint& paint) const; - void DrawHorizLine(SkCanvas* canvas, - int x1, - int x2, - int y, - const SkPaint& paint) const; - void DrawBox(SkCanvas* canvas, - const gfx::Rect& rect, - const SkPaint& paint) const; - SkScalar Clamp(SkScalar value, - SkScalar min, - SkScalar max) const; - SkColor OutlineColor(SkScalar* hsv1, SkScalar* hsv2) const; - - static unsigned int scrollbar_width_; - static unsigned int button_length_; - static unsigned int thumb_inactive_color_; - static unsigned int thumb_active_color_; - static unsigned int track_color_; - - DISALLOW_COPY_AND_ASSIGN(NativeThemeLinux); -}; - -} // namespace gfx +#include "ui/gfx/native_theme_linux.h" +// TODO(sail): remove this file once all includes have been updated. #endif // GFX_NATIVE_THEME_LINUX_H_ diff --git a/gfx/native_theme_win.h b/gfx/native_theme_win.h index 72a5432..c45b5fc 100644 --- a/gfx/native_theme_win.h +++ b/gfx/native_theme_win.h @@ -12,310 +12,7 @@ #define APP_GFX_NATIVE_THEME_WIN_H_ #pragma once -#include <windows.h> -#include <uxtheme.h> -#include "base/basictypes.h" -#include "gfx/size.h" -#include "third_party/skia/include/core/SkColor.h" - -namespace skia { -class PlatformCanvas; -} // namespace skia - -namespace gfx { - -// TODO: Define class member enums to replace part_id and state_id parameters -// that are currently defined in <vssym32.h>. Afterward, classic_state should -// be removed and class users wouldn't need to include <vssym32.h> anymore. -// This would enable HOT state on non-themed UI (like when RDP'ing) and would -// simplify usage. -// TODO: This class should probably be changed to be platform independent at -// the same time. -class NativeTheme { - public: - enum ThemeName { - BUTTON, - LIST, - MENU, - MENULIST, - SCROLLBAR, - STATUS, - TAB, - TEXTFIELD, - TRACKBAR, - WINDOW, - PROGRESS, - SPIN, - LAST - }; - - // This enumeration is used within PaintMenuArrow in order to indicate the - // direction the menu arrow should point to. - enum MenuArrowDirection { - LEFT_POINTING_ARROW, - RIGHT_POINTING_ARROW - }; - - enum ControlState { - CONTROL_NORMAL, - CONTROL_HIGHLIGHTED, - CONTROL_DISABLED - }; - - typedef HRESULT (WINAPI* DrawThemeBackgroundPtr)(HANDLE theme, - HDC hdc, - int part_id, - int state_id, - const RECT* rect, - const RECT* clip_rect); - typedef HRESULT (WINAPI* DrawThemeBackgroundExPtr)(HANDLE theme, - HDC hdc, - int part_id, - int state_id, - const RECT* rect, - const DTBGOPTS* opts); - typedef HRESULT (WINAPI* GetThemeColorPtr)(HANDLE hTheme, - int part_id, - int state_id, - int prop_id, - COLORREF* color); - typedef HRESULT (WINAPI* GetThemeContentRectPtr)(HANDLE hTheme, - HDC hdc, - int part_id, - int state_id, - const RECT* rect, - RECT* content_rect); - typedef HRESULT (WINAPI* GetThemePartSizePtr)(HANDLE hTheme, - HDC hdc, - int part_id, - int state_id, - RECT* rect, - int ts, - SIZE* size); - typedef HANDLE (WINAPI* OpenThemeDataPtr)(HWND window, - LPCWSTR class_list); - typedef HRESULT (WINAPI* CloseThemeDataPtr)(HANDLE theme); - - typedef void (WINAPI* SetThemeAppPropertiesPtr) (DWORD flags); - typedef BOOL (WINAPI* IsThemeActivePtr)(); - typedef HRESULT (WINAPI* GetThemeIntPtr)(HANDLE hTheme, - int part_id, - int state_id, - int prop_id, - int *value); - - HRESULT PaintButton(HDC hdc, - int part_id, - int state_id, - int classic_state, - RECT* rect) const; - - HRESULT PaintDialogBackground(HDC dc, bool active, RECT* rect) const; - - HRESULT PaintListBackground(HDC dc, bool enabled, RECT* rect) const; - - // |arrow_direction| determines whether the arrow is pointing to the left or - // to the right. In RTL locales, sub-menus open from right to left and - // therefore the menu arrow should point to the left and not to the right. - HRESULT PaintMenuArrow(ThemeName theme, - HDC hdc, - int part_id, - int state_id, - RECT* rect, - MenuArrowDirection arrow_direction, - ControlState state) const; - - HRESULT PaintMenuBackground(ThemeName theme, - HDC hdc, - int part_id, - int state_id, - RECT* rect) const; - - HRESULT PaintMenuCheck(ThemeName theme, - HDC hdc, - int part_id, - int state_id, - RECT* rect, - ControlState state) const; - - HRESULT PaintMenuCheckBackground(ThemeName theme, - HDC hdc, - int part_id, - int state_id, - RECT* rect) const; - - HRESULT PaintMenuGutter(HDC hdc, - int part_id, - int state_id, - RECT* rect) const; - - HRESULT PaintMenuItemBackground(ThemeName theme, - HDC hdc, - int part_id, - int state_id, - bool selected, - RECT* rect) const; - - HRESULT PaintMenuList(HDC hdc, - int part_id, - int state_id, - int classic_state, - RECT* rect) const; - - HRESULT PaintMenuSeparator(HDC hdc, - int part_id, - int state_id, - RECT* rect) const; - - // Paints a scrollbar arrow. |classic_state| should have the appropriate - // classic part number ORed in already. - HRESULT PaintScrollbarArrow(HDC hdc, - int state_id, - int classic_state, - RECT* rect) const; - - // Paints a scrollbar track section. |align_rect| is only used in classic - // mode, and makes sure the checkerboard pattern in |target_rect| is aligned - // with one presumed to be in |align_rect|. - HRESULT PaintScrollbarTrack(HDC hdc, - int part_id, - int state_id, - int classic_state, - RECT* target_rect, - RECT* align_rect, - skia::PlatformCanvas* canvas) const; - - // Paints a scrollbar thumb or gripper. - HRESULT PaintScrollbarThumb(HDC hdc, - int part_id, - int state_id, - int classic_state, - RECT* rect) const; - - HRESULT PaintSpinButton(HDC hdc, - int part_id, - int state_id, - int classic_state, - RECT* rect) const; - - HRESULT PaintStatusGripper(HDC hdc, - int part_id, - int state_id, - int classic_state, - RECT* rect) const; - - HRESULT PaintTabPanelBackground(HDC dc, RECT* rect) const; - - HRESULT PaintTextField(HDC hdc, - int part_id, - int state_id, - int classic_state, - RECT* rect, - COLORREF color, - bool fill_content_area, - bool draw_edges) const; - - HRESULT PaintTrackbar(HDC hdc, - int part_id, - int state_id, - int classic_state, - RECT* rect, - skia::PlatformCanvas* canvas) const; - - HRESULT PaintProgressBar(HDC hdc, - RECT* bar_rect, - RECT* value_rect, - bool determinate, - double animated_seconds, - skia::PlatformCanvas* canvas) const; - - bool IsThemingActive() const; - - HRESULT GetThemePartSize(ThemeName themeName, - HDC hdc, - int part_id, - int state_id, - RECT* rect, - int ts, - SIZE* size) const; - - HRESULT GetThemeColor(ThemeName theme, - int part_id, - int state_id, - int prop_id, - SkColor* color) const; - - // Get the theme color if theming is enabled. If theming is unsupported - // for this part, use Win32's GetSysColor to find the color specified - // by default_sys_color. - SkColor GetThemeColorWithDefault(ThemeName theme, - int part_id, - int state_id, - int prop_id, - int default_sys_color) const; - - HRESULT GetThemeInt(ThemeName theme, - int part_id, - int state_id, - int prop_id, - int *result) const; - - // Get the thickness of the border associated with the specified theme, - // defaulting to GetSystemMetrics edge size if themes are disabled. - // In Classic Windows, borders are typically 2px; on XP+, they are 1px. - Size GetThemeBorderSize(ThemeName theme) const; - - // Disables all theming for top-level windows in the entire process, from - // when this method is called until the process exits. All the other - // methods in this class will continue to work, but their output will ignore - // the user's theme. This is meant for use when running tests that require - // consistent visual results. - void DisableTheming() const; - - // Closes cached theme handles so we can unload the DLL or update our UI - // for a theme change. - void CloseHandles() const; - - // Returns true if classic theme is in use. - bool IsClassicTheme(ThemeName name) const; - - // Gets our singleton instance. - static const NativeTheme* instance(); - - private: - NativeTheme(); - ~NativeTheme(); - - HRESULT PaintFrameControl(HDC hdc, - RECT* rect, - UINT type, - UINT state, - ControlState control_state) const; - - // Returns a handle to the theme data. - HANDLE GetThemeHandle(ThemeName theme_name) const; - - // Function pointers into uxtheme.dll. - DrawThemeBackgroundPtr draw_theme_; - DrawThemeBackgroundExPtr draw_theme_ex_; - GetThemeColorPtr get_theme_color_; - GetThemeContentRectPtr get_theme_content_rect_; - GetThemePartSizePtr get_theme_part_size_; - OpenThemeDataPtr open_theme_; - CloseThemeDataPtr close_theme_; - SetThemeAppPropertiesPtr set_theme_properties_; - IsThemeActivePtr is_theme_active_; - GetThemeIntPtr get_theme_int_; - - // Handle to uxtheme.dll. - HMODULE theme_dll_; - - // A cache of open theme handles. - mutable HANDLE theme_handles_[LAST]; - - DISALLOW_COPY_AND_ASSIGN(NativeTheme); -}; - -} // namespace gfx +#include "ui/gfx/native_theme_win.h" +// TODO(sail): remove this file once all includes have been updated. #endif // APP_GFX_NATIVE_THEME_WIN_H_ diff --git a/gfx/native_widget_types.h b/gfx/native_widget_types.h index 89b091b..f8ff236 100644 --- a/gfx/native_widget_types.h +++ b/gfx/native_widget_types.h @@ -6,171 +6,7 @@ #define GFX_NATIVE_WIDGET_TYPES_H_ #pragma once -#include "base/basictypes.h" -#include "build/build_config.h" - -// This file provides cross platform typedefs for native widget types. -// NativeWindow: this is a handle to a native, top-level window -// NativeView: this is a handle to a native UI element. It may be the -// same type as a NativeWindow on some platforms. -// NativeViewId: Often, in our cross process model, we need to pass around a -// reference to a "window". This reference will, say, be echoed back from a -// renderer to the browser when it wishes to query its size. On Windows we -// use an HWND for this. -// -// As a rule of thumb - if you're in the renderer, you should be dealing -// with NativeViewIds. This should remind you that you shouldn't be doing -// direct operations on platform widgets from the renderer process. -// -// If you're in the browser, you're probably dealing with NativeViews, -// unless you're in the IPC layer, which will be translating between -// NativeViewIds from the renderer and NativeViews. -// -// NativeEditView: a handle to a native edit-box. The Mac folks wanted this -// specific typedef. -// -// NativeImage: The platform-specific image type used for drawing UI elements -// in the browser. -// -// The name 'View' here meshes with OS X where the UI elements are called -// 'views' and with our Chrome UI code where the elements are also called -// 'views'. - -#if defined(OS_WIN) -#include <windows.h> // NOLINT -typedef struct HFONT__* HFONT; -#elif defined(OS_MACOSX) -struct CGContext; -#ifdef __OBJC__ -@class NSFont; -@class NSImage; -@class NSView; -@class NSWindow; -@class NSTextField; -#else -class NSFont; -class NSImage; -class NSView; -class NSWindow; -class NSTextField; -#endif // __OBJC__ -#elif defined(TOOLKIT_USES_GTK) -typedef struct _PangoFontDescription PangoFontDescription; -typedef struct _GdkCursor GdkCursor; -typedef struct _GdkPixbuf GdkPixbuf; -typedef struct _GdkRegion GdkRegion; -typedef struct _GtkWidget GtkWidget; -typedef struct _GtkWindow GtkWindow; -typedef struct _cairo cairo_t; -#endif -class SkBitmap; - -namespace gfx { - -#if defined(OS_WIN) -typedef HFONT NativeFont; -typedef HWND NativeView; -typedef HWND NativeWindow; -typedef HWND NativeEditView; -typedef HDC NativeDrawingContext; -typedef HCURSOR NativeCursor; -typedef HMENU NativeMenu; -typedef HRGN NativeRegion; -#elif defined(OS_MACOSX) -typedef NSFont* NativeFont; -typedef NSView* NativeView; -typedef NSWindow* NativeWindow; -typedef NSTextField* NativeEditView; -typedef CGContext* NativeDrawingContext; -typedef void* NativeCursor; -typedef void* NativeMenu; -#elif defined(USE_X11) -typedef PangoFontDescription* NativeFont; -typedef GtkWidget* NativeView; -typedef GtkWindow* NativeWindow; -typedef GtkWidget* NativeEditView; -typedef cairo_t* NativeDrawingContext; -typedef GdkCursor* NativeCursor; -typedef GtkWidget* NativeMenu; -typedef GdkRegion* NativeRegion; -#endif - -#if defined(OS_MACOSX) -typedef NSImage NativeImageType; -#elif defined(OS_LINUX) && !defined(TOOLKIT_VIEWS) -typedef GdkPixbuf NativeImageType; -#else -typedef SkBitmap NativeImageType; -#endif -typedef NativeImageType* NativeImage; - -// Note: for test_shell we're packing a pointer into the NativeViewId. So, if -// you make it a type which is smaller than a pointer, you have to fix -// test_shell. -// -// See comment at the top of the file for usage. -typedef intptr_t NativeViewId; - -#if defined(OS_WIN) -// Convert a NativeViewId to a NativeView. -// -// On Windows, we pass an HWND into the renderer. As stated above, the renderer -// should not be performing operations on the view. -static inline NativeView NativeViewFromId(NativeViewId id) { - return reinterpret_cast<NativeView>(id); -} -#define NativeViewFromIdInBrowser(x) NativeViewFromId(x) -#elif defined(OS_POSIX) -// On Mac and Linux, a NativeView is a pointer to an object, and is useless -// outside the process in which it was created. NativeViewFromId should only be -// used inside the appropriate platform ifdef outside of the browser. -// (NativeViewFromIdInBrowser can be used everywhere in the browser.) If your -// cross-platform design involves a call to NativeViewFromId from outside the -// browser it will never work on Mac or Linux and is fundamentally broken. - -// Please do not call this from outside the browser. It won't work; the name -// should give you a subtle hint. -static inline NativeView NativeViewFromIdInBrowser(NativeViewId id) { - return reinterpret_cast<NativeView>(id); -} -#endif // defined(OS_POSIX) - -// Convert a NativeView to a NativeViewId. See the comments at the top of -// this file. -#if defined(OS_WIN) || defined(OS_MACOSX) -static inline NativeViewId IdFromNativeView(NativeView view) { - return reinterpret_cast<NativeViewId>(view); -} -#elif defined(USE_X11) -// Not inlined because it involves pulling too many headers. -NativeViewId IdFromNativeView(NativeView view); -#endif // defined(USE_X11) - - -// PluginWindowHandle is an abstraction wrapping "the types of windows -// used by NPAPI plugins". On Windows it's an HWND, on X it's an X -// window id. -#if defined(OS_WIN) - typedef HWND PluginWindowHandle; - const PluginWindowHandle kNullPluginWindow = NULL; -#elif defined(USE_X11) - typedef unsigned long PluginWindowHandle; - const PluginWindowHandle kNullPluginWindow = 0; -#else - // On OS X we don't have windowed plugins. - // We use a NULL/0 PluginWindowHandle in shared code to indicate there - // is no window present, so mirror that behavior here. - // - // The GPU plugin is currently an exception to this rule. As of this - // writing it uses some NPAPI infrastructure, and minimally we need - // to identify the plugin instance via this window handle. When the - // GPU plugin becomes a full-on GPU process, this typedef can be - // returned to a bool. For now we use a type large enough to hold a - // pointer on 64-bit architectures in case we need this capability. - typedef uint64 PluginWindowHandle; - const PluginWindowHandle kNullPluginWindow = 0; -#endif - -} // namespace gfx +#include "ui/gfx/native_widget_types.h" +// TODO(sail): remove this file once all includes have been updated. #endif // GFX_NATIVE_WIDGET_TYPES_H_ @@ -6,52 +6,7 @@ #define GFX_PATH_H_ #pragma once -#include "base/basictypes.h" -#include "gfx/native_widget_types.h" - -#include "third_party/skia/include/core/SkPath.h" - -namespace gfx { - -class Path : public SkPath { - public: - // Used by Path(Point,size_t) constructor. - struct Point { - int x; - int y; - }; - - Path(); - - // Creates a path populated with the specified points. - Path(const Point* points, size_t count); - - ~Path(); - -#if defined(OS_WIN) || defined(USE_X11) - // Creates a NativeRegion from the path. The caller is responsible for freeing - // resources used by this region. This only supports polygon paths. - NativeRegion CreateNativeRegion() const; - - // Returns the intersection of the two regions. The caller owns the returned - // object. - static gfx::NativeRegion IntersectRegions(gfx::NativeRegion r1, - gfx::NativeRegion r2); - - // Returns the union of the two regions. The caller owns the returned object. - static gfx::NativeRegion CombineRegions(gfx::NativeRegion r1, - gfx::NativeRegion r2); - - // Returns the difference of the two regions. The caller owns the returned - // object. - static gfx::NativeRegion SubtractRegion(gfx::NativeRegion r1, - gfx::NativeRegion r2); -#endif - - private: - DISALLOW_COPY_AND_ASSIGN(Path); -}; - -} +#include "ui/gfx/path.h" +// TODO(sail): remove this file once all includes have been updated. #endif // GFX_PATH_H_ diff --git a/gfx/platform_font.h b/gfx/platform_font.h index 412e260..2a88fff 100644 --- a/gfx/platform_font.h +++ b/gfx/platform_font.h @@ -6,74 +6,8 @@ #define GFX_PLATFORM_FONT_ #pragma once -#include <string> - -#include "base/ref_counted.h" -#include "base/string16.h" -#include "gfx/native_widget_types.h" - -namespace gfx { - -class Font; - -class PlatformFont : public base::RefCounted<PlatformFont> { - public: - // Create an appropriate PlatformFont implementation. - static PlatformFont* CreateDefault(); - static PlatformFont* CreateFromFont(const Font& other); - static PlatformFont* CreateFromNativeFont(NativeFont native_font); - static PlatformFont* CreateFromNameAndSize(const string16& font_name, - int font_size); - - // Returns a new Font derived from the existing font. - // size_delta is the size to add to the current font. See the single - // argument version of this method for an example. - // The style parameter specifies the new style for the font, and is a - // bitmask of the values: BOLD, ITALIC and UNDERLINED. - virtual Font DeriveFont(int size_delta, int style) const = 0; - - // Returns the number of vertical pixels needed to display characters from - // the specified font. This may include some leading, i.e. height may be - // greater than just ascent + descent. Specifically, the Windows and Mac - // implementations include leading and the Linux one does not. This may - // need to be revisited in the future. - virtual int GetHeight() const = 0; - - // Returns the baseline, or ascent, of the font. - virtual int GetBaseline() const = 0; - - // Returns the average character width for the font. - virtual int GetAverageCharacterWidth() const = 0; - - // Returns the number of horizontal pixels needed to display the specified - // string. - virtual int GetStringWidth(const string16& text) const = 0; - - // Returns the expected number of horizontal pixels needed to display the - // specified length of characters. Call GetStringWidth() to retrieve the - // actual number. - virtual int GetExpectedTextWidth(int length) const = 0; - - // Returns the style of the font. - virtual int GetStyle() const = 0; - - // Returns the font name. - virtual string16 GetFontName() const = 0; - - // Returns the font size in pixels. - virtual int GetFontSize() const = 0; - - // Returns the native font handle. - virtual NativeFont GetNativeFont() const = 0; - - protected: - virtual ~PlatformFont() {} - - private: - friend class base::RefCounted<PlatformFont>; -}; - -} // namespace gfx +#include "ui/gfx/platform_font.h" +// TODO(sail): remove this file once all includes have been updated. #endif // GFX_PLATFORM_FONT_ diff --git a/gfx/platform_font_gtk.h b/gfx/platform_font_gtk.h index e69c24a..b87df6c 100644 --- a/gfx/platform_font_gtk.h +++ b/gfx/platform_font_gtk.h @@ -6,102 +6,7 @@ #define GFX_PLATFORM_FONT_GTK_ #pragma once -#include "base/scoped_ptr.h" -#include "gfx/platform_font.h" -#include "third_party/skia/include/core/SkRefCnt.h" - -class SkTypeface; -class SkPaint; - -namespace gfx { - -class PlatformFontGtk : public PlatformFont { - public: - PlatformFontGtk(); - explicit PlatformFontGtk(const Font& other); - explicit PlatformFontGtk(NativeFont native_font); - PlatformFontGtk(const string16& font_name, - int font_size); - - // Converts |gfx_font| to a new pango font. Free the returned font with - // pango_font_description_free(). - static PangoFontDescription* PangoFontFromGfxFont(const gfx::Font& gfx_font); - - // Position as an offset from the height of the drawn text, used to draw - // an underline. This is a negative number, so the underline would be - // drawn at y + height + underline_position; - double underline_position() const; - // The thickness to draw the underline. - double underline_thickness() const; - - // Overridden from PlatformFont: - virtual Font DeriveFont(int size_delta, int style) const; - virtual int GetHeight() const; - virtual int GetBaseline() const; - virtual int GetAverageCharacterWidth() const; - virtual int GetStringWidth(const string16& text) const; - virtual int GetExpectedTextWidth(int length) const; - virtual int GetStyle() const; - virtual string16 GetFontName() const; - virtual int GetFontSize() const; - virtual NativeFont GetNativeFont() const; - - private: - // Create a new instance of this object with the specified properties. Called - // from DeriveFont. - PlatformFontGtk(SkTypeface* typeface, - const string16& name, - int size, - int style); - virtual ~PlatformFontGtk(); - - // Initialize this object. - void InitWithNameAndSize(const string16& font_name, int font_size); - void InitWithTypefaceNameSizeAndStyle(SkTypeface* typeface, - const string16& name, - int size, - int style); - void InitFromPlatformFont(const PlatformFontGtk* other); - - // Potentially slow call to get pango metrics (average width, underline info). - void InitPangoMetrics(); - - // Setup a Skia context to use the current typeface - void PaintSetup(SkPaint* paint) const; - - // Make |this| a copy of |other|. - void CopyFont(const Font& other); - - // The average width of a character, initialized and cached if needed. - double GetAverageWidth() const; - - // These two both point to the same SkTypeface. We use the SkAutoUnref to - // handle the reference counting, but without @typeface_ we would have to - // cast the SkRefCnt from @typeface_helper_ every time. - scoped_ptr<SkAutoUnref> typeface_helper_; - SkTypeface *typeface_; - - // Additional information about the face - // Skia actually expects a family name and not a font name. - string16 font_family_; - int font_size_pixels_; - int style_; - - // Cached metrics, generated at construction - int height_pixels_; - int ascent_pixels_; - - // The pango metrics are much more expensive so we wait until we need them - // to compute them. - bool pango_metrics_inited_; - double average_width_pixels_; - double underline_position_pixels_; - double underline_thickness_pixels_; - - // The default font, used for the default constructor. - static Font* default_font_; -}; - -} // namespace gfx +#include "ui/gfx/platform_font_gtk.h" +// TODO(sail): remove this file once all includes have been updated. #endif // GFX_PLATFORM_FONT_GTK_ diff --git a/gfx/platform_font_mac.h b/gfx/platform_font_mac.h index 62f44b6..8f676d7 100644 --- a/gfx/platform_font_mac.h +++ b/gfx/platform_font_mac.h @@ -6,52 +6,7 @@ #define GFX_PLATFORM_FONT_MAC_ #pragma once -#include "gfx/platform_font.h" - -namespace gfx { - -class PlatformFontMac : public PlatformFont { - public: - PlatformFontMac(); - explicit PlatformFontMac(const Font& other); - explicit PlatformFontMac(NativeFont native_font); - PlatformFontMac(const string16& font_name, - int font_size); - - // Overridden from PlatformFont: - virtual Font DeriveFont(int size_delta, int style) const; - virtual int GetHeight() const; - virtual int GetBaseline() const; - virtual int GetAverageCharacterWidth() const; - virtual int GetStringWidth(const string16& text) const; - virtual int GetExpectedTextWidth(int length) const; - virtual int GetStyle() const; - virtual string16 GetFontName() const; - virtual int GetFontSize() const; - virtual NativeFont GetNativeFont() const; - - private: - PlatformFontMac(const string16& font_name, int font_size, int style); - virtual ~PlatformFontMac() {} - - // Initialize the object with the specified parameters. - void InitWithNameSizeAndStyle(const string16& font_name, - int font_size, - int style); - - // Calculate and cache the font metrics. - void CalculateMetrics(); - - string16 font_name_; - int font_size_; - int style_; - - // Cached metrics, generated at construction - int height_; - int ascent_; - int average_width_; -}; - -} // namespace gfx +#include "ui/gfx/platform_font_mac.h" +// TODO(sail): remove this file once all includes have been updated. #endif // GFX_PLATFORM_FONT_MAC_ diff --git a/gfx/platform_font_win.h b/gfx/platform_font_win.h index 4adaa38..b491e80 100644 --- a/gfx/platform_font_win.h +++ b/gfx/platform_font_win.h @@ -6,126 +6,7 @@ #define GFX_PLATFORM_FONT_WIN_ #pragma once -#include "base/ref_counted.h" -#include "gfx/platform_font.h" - -namespace gfx { - -class PlatformFontWin : public PlatformFont { - public: - PlatformFontWin(); - explicit PlatformFontWin(const Font& other); - explicit PlatformFontWin(NativeFont native_font); - PlatformFontWin(const string16& font_name, - int font_size); - - // Dialog units to pixels conversion. - // See http://support.microsoft.com/kb/145994 for details. - int horizontal_dlus_to_pixels(int dlus) const { - return dlus * font_ref_->dlu_base_x() / 4; - } - int vertical_dlus_to_pixels(int dlus) const { - return dlus * font_ref_->height() / 8; - } - - // Callback that returns the minimum height that should be used for - // gfx::Fonts. Optional. If not specified, the minimum font size is 0. - typedef int (*GetMinimumFontSizeCallback)(); - static GetMinimumFontSizeCallback get_minimum_font_size_callback; - - // Callback that adjusts a LOGFONT to meet suitability requirements of the - // embedding application. Optional. If not specified, no adjustments are - // performed other than clamping to a minimum font height if - // |get_minimum_font_size_callback| is specified. - typedef void (*AdjustFontCallback)(LOGFONT* lf); - static AdjustFontCallback adjust_font_callback; - - // Overridden from PlatformFont: - virtual Font DeriveFont(int size_delta, int style) const; - virtual int GetHeight() const; - virtual int GetBaseline() const; - virtual int GetAverageCharacterWidth() const; - virtual int GetStringWidth(const string16& text) const; - virtual int GetExpectedTextWidth(int length) const; - virtual int GetStyle() const; - virtual string16 GetFontName() const; - virtual int GetFontSize() const; - virtual NativeFont GetNativeFont() const; - - private: - virtual ~PlatformFontWin() {} - - // Chrome text drawing bottoms out in the Windows GDI functions that take an - // HFONT (an opaque handle into Windows). To avoid lots of GDI object - // allocation and destruction, Font indirectly refers to the HFONT by way of - // an HFontRef. That is, every Font has an HFontRef, which has an HFONT. - // - // HFontRef is reference counted. Upon deletion, it deletes the HFONT. - // By making HFontRef maintain the reference to the HFONT, multiple - // HFontRefs can share the same HFONT, and Font can provide value semantics. - class HFontRef : public base::RefCounted<HFontRef> { - public: - // This constructor takes control of the HFONT, and will delete it when - // the HFontRef is deleted. - HFontRef(HFONT hfont, - int height, - int baseline, - int ave_char_width, - int style, - int dlu_base_x); - - // Accessors - HFONT hfont() const { return hfont_; } - int height() const { return height_; } - int baseline() const { return baseline_; } - int ave_char_width() const { return ave_char_width_; } - int style() const { return style_; } - int dlu_base_x() const { return dlu_base_x_; } - const string16& font_name() const { return font_name_; } - - private: - friend class base::RefCounted<HFontRef>; - - ~HFontRef(); - - const HFONT hfont_; - const int height_; - const int baseline_; - const int ave_char_width_; - const int style_; - // Constants used in converting dialog units to pixels. - const int dlu_base_x_; - string16 font_name_; - - DISALLOW_COPY_AND_ASSIGN(HFontRef); - }; - - // Initializes this object with a copy of the specified HFONT. - void InitWithCopyOfHFONT(HFONT hfont); - - // Initializes this object with the specified font name and size. - void InitWithFontNameAndSize(const string16& font_name, - int font_size); - - // Returns the base font ref. This should ONLY be invoked on the - // UI thread. - static HFontRef* GetBaseFontRef(); - - // Creates and returns a new HFONTRef from the specified HFONT. - static HFontRef* CreateHFontRef(HFONT font); - - // Creates a new PlatformFontWin with the specified HFontRef. Used when - // constructing a Font from a HFONT we don't want to copy. - explicit PlatformFontWin(HFontRef* hfont_ref); - - // Reference to the base font all fonts are derived from. - static HFontRef* base_font_ref_; - - // Indirect reference to the HFontRef, which references the underlying HFONT. - scoped_refptr<HFontRef> font_ref_; -}; - -} // namespace gfx +#include "ui/gfx/platform_font_win.h" +// TODO(sail): remove this file once all includes have been updated. #endif // GFX_PLATFORM_FONT_WIN_ - diff --git a/gfx/point.h b/gfx/point.h index a2c10ad..ff313c7 100644 --- a/gfx/point.h +++ b/gfx/point.h @@ -6,96 +6,7 @@ #define GFX_POINT_H_ #pragma once -#include "build/build_config.h" - -#include <iosfwd> - -#if defined(OS_WIN) -typedef unsigned long DWORD; -typedef struct tagPOINT POINT; -#elif defined(OS_MACOSX) -#include <ApplicationServices/ApplicationServices.h> -#endif - -namespace gfx { - -// A point has an x and y coordinate. -class Point { - public: - Point(); - Point(int x, int y); -#if defined(OS_WIN) - // |point| is a DWORD value that contains a coordinate. The x-coordinate is - // the low-order short and the y-coordinate is the high-order short. This - // value is commonly acquired from GetMessagePos/GetCursorPos. - explicit Point(DWORD point); - explicit Point(const POINT& point); - Point& operator=(const POINT& point); -#elif defined(OS_MACOSX) - explicit Point(const CGPoint& point); -#endif - - ~Point() {} - - int x() const { return x_; } - int y() const { return y_; } - - void SetPoint(int x, int y) { - x_ = x; - y_ = y; - } - - void set_x(int x) { x_ = x; } - void set_y(int y) { y_ = y; } - - void Offset(int delta_x, int delta_y) { - x_ += delta_x; - y_ += delta_y; - } - - Point Add(const Point& other) const{ - Point copy = *this; - copy.Offset(other.x_, other.y_); - return copy; - } - - Point Subtract(const Point& other) const { - Point copy = *this; - copy.Offset(-other.x_, -other.y_); - return copy; - } - - bool operator==(const Point& rhs) const { - return x_ == rhs.x_ && y_ == rhs.y_; - } - - bool operator!=(const Point& rhs) const { - return !(*this == rhs); - } - - // A point is less than another point if its y-value is closer - // to the origin. If the y-values are the same, then point with - // the x-value closer to the origin is considered less than the - // other. - // This comparison is required to use Points in sets, or sorted - // vectors. - bool operator<(const Point& rhs) const { - return (y_ == rhs.y_) ? (x_ < rhs.x_) : (y_ < rhs.y_); - } - -#if defined(OS_WIN) - POINT ToPOINT() const; -#elif defined(OS_MACOSX) - CGPoint ToCGPoint() const; -#endif - - private: - int x_; - int y_; -}; - -std::ostream& operator<<(std::ostream& out, const gfx::Point& p); - -} // namespace gfx +#include "ui/gfx/point.h" +// TODO(sail): remove this file once all includes have been updated. #endif // GFX_POINT_H_ @@ -13,172 +13,7 @@ #define GFX_RECT_H_ #pragma once -#include <iosfwd> - -#include "gfx/point.h" -#include "gfx/size.h" - -#if defined(OS_WIN) -typedef struct tagRECT RECT; -#elif defined(USE_X11) -typedef struct _GdkRectangle GdkRectangle; -#endif - -namespace gfx { - -class Insets; - -class Rect { - public: - Rect(); - Rect(int width, int height); - Rect(int x, int y, int width, int height); -#if defined(OS_WIN) - explicit Rect(const RECT& r); -#elif defined(OS_MACOSX) - explicit Rect(const CGRect& r); -#elif defined(USE_X11) - explicit Rect(const GdkRectangle& r); -#endif - explicit Rect(const gfx::Size& size); - Rect(const gfx::Point& origin, const gfx::Size& size); - - ~Rect() {} - -#if defined(OS_WIN) - Rect& operator=(const RECT& r); -#elif defined(OS_MACOSX) - Rect& operator=(const CGRect& r); -#elif defined(USE_X11) - Rect& operator=(const GdkRectangle& r); -#endif - - int x() const { return origin_.x(); } - void set_x(int x) { origin_.set_x(x); } - - int y() const { return origin_.y(); } - void set_y(int y) { origin_.set_y(y); } - - int width() const { return size_.width(); } - void set_width(int width) { size_.set_width(width); } - - int height() const { return size_.height(); } - void set_height(int height) { size_.set_height(height); } - - const gfx::Point& origin() const { return origin_; } - void set_origin(const gfx::Point& origin) { origin_ = origin; } - - const gfx::Size& size() const { return size_; } - void set_size(const gfx::Size& size) { size_ = size; } - - int right() const { return x() + width(); } - int bottom() const { return y() + height(); } - - void SetRect(int x, int y, int width, int height); - - // Shrink the rectangle by a horizontal and vertical distance on all sides. - void Inset(int horizontal, int vertical) { - Inset(horizontal, vertical, horizontal, vertical); - } - - // Shrink the rectangle by the given insets. - void Inset(const gfx::Insets& insets); - - // Shrink the rectangle by the specified amount on each side. - void Inset(int left, int top, int right, int bottom); - - // Move the rectangle by a horizontal and vertical distance. - void Offset(int horizontal, int vertical); - void Offset(const gfx::Point& point) { - Offset(point.x(), point.y()); - } - - // Returns true if the area of the rectangle is zero. - bool IsEmpty() const { return size_.IsEmpty(); } - - bool operator==(const Rect& other) const; - - bool operator!=(const Rect& other) const { - return !(*this == other); - } - - // A rect is less than another rect if its origin is less than - // the other rect's origin. If the origins are equal, then the - // shortest rect is less than the other. If the origin and the - // height are equal, then the narrowest rect is less than. - // This comparison is required to use Rects in sets, or sorted - // vectors. - bool operator<(const Rect& other) const; - -#if defined(OS_WIN) - // Construct an equivalent Win32 RECT object. - RECT ToRECT() const; -#elif defined(USE_X11) - GdkRectangle ToGdkRectangle() const; -#elif defined(OS_MACOSX) - // Construct an equivalent CoreGraphics object. - CGRect ToCGRect() const; -#endif - - // Returns true if the point identified by point_x and point_y falls inside - // this rectangle. The point (x, y) is inside the rectangle, but the - // point (x + width, y + height) is not. - bool Contains(int point_x, int point_y) const; - - // Returns true if the specified point is contained by this rectangle. - bool Contains(const gfx::Point& point) const { - return Contains(point.x(), point.y()); - } - - // Returns true if this rectangle contains the specified rectangle. - bool Contains(const Rect& rect) const; - - // Returns true if this rectangle intersects the specified rectangle. - bool Intersects(const Rect& rect) const; - - // Computes the intersection of this rectangle with the given rectangle. - Rect Intersect(const Rect& rect) const; - - // Computes the union of this rectangle with the given rectangle. The union - // is the smallest rectangle containing both rectangles. - Rect Union(const Rect& rect) const; - - // Computes the rectangle resulting from subtracting |rect| from |this|. If - // |rect| does not intersect completely in either the x- or y-direction, then - // |*this| is returned. If |rect| contains |this|, then an empty Rect is - // returned. - Rect Subtract(const Rect& rect) const; - - // Returns true if this rectangle equals that of the supplied rectangle. - bool Equals(const Rect& rect) const { - return *this == rect; - } - - // Fits as much of the receiving rectangle into the supplied rectangle as - // possible, returning the result. For example, if the receiver had - // a x-location of 2 and a width of 4, and the supplied rectangle had - // an x-location of 0 with a width of 5, the returned rectangle would have - // an x-location of 1 with a width of 4. - Rect AdjustToFit(const Rect& rect) const; - - // Returns the center of this rectangle. - Point CenterPoint() const; - - // Return a rectangle that has the same center point but with a size capped - // at given |size|. - Rect Center(const gfx::Size& size) const; - - // Returns true if this rectangle shares an entire edge (i.e., same width or - // same height) with the given rectangle, and the rectangles do not overlap. - bool SharesEdgeWith(const gfx::Rect& rect) const; - - private: - gfx::Point origin_; - gfx::Size size_; -}; - -std::ostream& operator<<(std::ostream& out, const gfx::Rect& r); - -} // namespace gfx +#include "ui/gfx/rect.h" +// TODO(sail): remove this file once all includes have been updated. #endif // GFX_RECT_H_ diff --git a/gfx/scoped_cg_context_state_mac.h b/gfx/scoped_cg_context_state_mac.h index 4ba7fac..f661efe 100644 --- a/gfx/scoped_cg_context_state_mac.h +++ b/gfx/scoped_cg_context_state_mac.h @@ -5,26 +5,7 @@ #ifndef GFX_SCOPED_CG_CONTEXT_STATE_MAC_H_ #define GFX_SCOPED_CG_CONTEXT_STATE_MAC_H_ -#import <QuartzCore/QuartzCore.h> - -namespace gfx { - -class ScopedCGContextSaveGState { - public: - explicit ScopedCGContextSaveGState(CGContextRef context) : context_(context) { - CGContextSaveGState(context_); - } - - ~ScopedCGContextSaveGState() { - CGContextRestoreGState(context_); - } - - private: - CGContextRef context_; - - DISALLOW_COPY_AND_ASSIGN(ScopedCGContextSaveGState); -}; - -} // namespace gfx +#include "ui/gfx/scoped_cg_context_state_mac.h" +// TODO(sail): remove this file once all includes have been updated. #endif // GFX_SCOPED_CG_CONTEXT_STATE_MAC_H_ diff --git a/gfx/scoped_image.h b/gfx/scoped_image.h index 56e99b7..686f249 100644 --- a/gfx/scoped_image.h +++ b/gfx/scoped_image.h @@ -6,142 +6,7 @@ #define GFX_SCOPED_IMAGE_H_ #pragma once -#include "base/basictypes.h" -#include "build/build_config.h" -#include "gfx/native_widget_types.h" -#include "third_party/skia/include/core/SkBitmap.h" - -#if defined(OS_LINUX) -#include <glib-object.h> -#elif defined(OS_MACOSX) -#include "base/mac/mac_util.h" -#endif - -namespace gfx { - -namespace internal { - -// ScopedImage is class that encapsulates one of the three platform-specific -// images used: SkBitmap, NSImage, and GdkPixbuf. This is the abstract interface -// that all ScopedImages respond to. This wrapper expects to own the image it -// holds, unless it is Release()ed or Free()ed. -// -// This class is abstract and callers should use the specialized versions below, -// which are not in the internal namespace. -template <class ImageType> -class ScopedImage { - public: - virtual ~ScopedImage() {} - - // Frees the actual image that this boxes. - virtual void Free() = 0; - - // Returns the image that this boxes. - ImageType* Get() { - return image_; - } - - // Frees the current image and sets a new one. - void Set(ImageType* new_image) { - Free(); - image_ = new_image; - } - - // Returns the image this boxes and relinquishes ownership. - ImageType* Release() { - ImageType* tmp = image_; - image_ = NULL; - return tmp; - } - - protected: - explicit ScopedImage(ImageType* image) : image_(image) {} - ImageType* image_; - - private: - DISALLOW_COPY_AND_ASSIGN(ScopedImage); -}; - -} // namespace internal - -// Generic template. -template <class ImageType = gfx::NativeImageType> -class ScopedImage : public gfx::internal::ScopedImage<ImageType> { - public: - explicit ScopedImage(gfx::NativeImage image) - : gfx::internal::ScopedImage<ImageType>(image) {} - - private: - DISALLOW_COPY_AND_ASSIGN(ScopedImage<ImageType>); -}; - -// Specialization for SkBitmap on all platforms. -template <> -class ScopedImage<SkBitmap> : public gfx::internal::ScopedImage<SkBitmap> { - public: - explicit ScopedImage(SkBitmap* image) - : gfx::internal::ScopedImage<SkBitmap>(image) {} - virtual ~ScopedImage() { - Free(); - } - - virtual void Free() { - delete image_; - image_ = NULL; - } - - private: - DISALLOW_COPY_AND_ASSIGN(ScopedImage); -}; - -// Specialization for the NSImage type on Mac OS X. -#if defined(OS_MACOSX) -template <> -class ScopedImage<NSImage> : public gfx::internal::ScopedImage<NSImage> { - public: - explicit ScopedImage(NSImage* image) - : gfx::internal::ScopedImage<NSImage>(image) {} - virtual ~ScopedImage() { - Free(); - } - - virtual void Free() { - base::mac::NSObjectRelease(image_); - image_ = NULL; - } - - private: - DISALLOW_COPY_AND_ASSIGN(ScopedImage); -}; -#endif // defined(OS_MACOSX) - -// Specialization for the GdkPixbuf type on Linux. -#if defined(OS_LINUX) -template <> -class ScopedImage<GdkPixbuf> : public gfx::internal::ScopedImage<GdkPixbuf> { - public: - explicit ScopedImage(GdkPixbuf* image) - : gfx::internal::ScopedImage<GdkPixbuf>(image) {} - virtual ~ScopedImage() { - Free(); - } - - virtual void Free() { - if (image_) { - g_object_unref(image_); - image_ = NULL; - } - } - - private: - DISALLOW_COPY_AND_ASSIGN(ScopedImage); -}; -#endif // defined(OS_LINUX) - -// Typedef ScopedNativeImage to the default template argument. This allows for -// easy exchange between gfx::NativeImage and a gfx::ScopedNativeImage. -typedef ScopedImage<> ScopedNativeImage; - -} // namespace gfx +#include "ui/gfx/scoped_image.h" +// TODO(sail): remove this file once all includes have been updated. #endif // GFX_SCOPED_IMAGE_H_ diff --git a/gfx/scrollbar_size.h b/gfx/scrollbar_size.h index 9b4a9c4..2bf70b9 100644 --- a/gfx/scrollbar_size.h +++ b/gfx/scrollbar_size.h @@ -6,13 +6,7 @@ #define GFX_SCROLLBAR_SIZE_H_ #pragma once -namespace gfx { - -// This should return the thickness, in pixels, of a scrollbar in web content. -// This needs to match the values in WebCore's -// ScrollbarThemeChromiumXXX.cpp::scrollbarThickness(). -int scrollbar_size(); - -} // namespace gfx +#include "ui/gfx/scrollbar_size.h" +// TODO(sail): remove this file once all includes have been updated. #endif // GFX_SCROLLBAR_SIZE_H_ @@ -6,77 +6,7 @@ #define GFX_SIZE_H_ #pragma once -#include "build/build_config.h" - -#include <iosfwd> - -#if defined(OS_WIN) -typedef struct tagSIZE SIZE; -#elif defined(OS_MACOSX) -#include <ApplicationServices/ApplicationServices.h> -#endif - -namespace gfx { - -// A size has width and height values. -class Size { - public: - Size() : width_(0), height_(0) {} - Size(int width, int height); -#if defined(OS_MACOSX) - explicit Size(const CGSize& s); -#endif - - ~Size() {} - -#if defined(OS_MACOSX) - Size& operator=(const CGSize& s); -#endif - - int width() const { return width_; } - int height() const { return height_; } - - int GetArea() const { return width_ * height_; } - - void SetSize(int width, int height) { - set_width(width); - set_height(height); - } - - void Enlarge(int width, int height) { - set_width(width_ + width); - set_height(height_ + height); - } - - void set_width(int width); - void set_height(int height); - - bool operator==(const Size& s) const { - return width_ == s.width_ && height_ == s.height_; - } - - bool operator!=(const Size& s) const { - return !(*this == s); - } - - bool IsEmpty() const { - // Size doesn't allow negative dimensions, so testing for 0 is enough. - return (width_ == 0) || (height_ == 0); - } - -#if defined(OS_WIN) - SIZE ToSIZE() const; -#elif defined(OS_MACOSX) - CGSize ToCGSize() const; -#endif - - private: - int width_; - int height_; -}; - -std::ostream& operator<<(std::ostream& out, const gfx::Size& s); - -} // namespace gfx +#include "ui/gfx/size.h" +// TODO(sail): remove this file once all includes have been updated. #endif // GFX_SIZE_H_ diff --git a/gfx/skbitmap_operations.h b/gfx/skbitmap_operations.h index e64c1aa..42aa7b3 100644 --- a/gfx/skbitmap_operations.h +++ b/gfx/skbitmap_operations.h @@ -6,97 +6,7 @@ #define GFX_SKBITMAP_OPERATIONS_H_ #pragma once -#include "base/gtest_prod_util.h" -#include "gfx/color_utils.h" - -class SkBitmap; - -class SkBitmapOperations { - public: - // Create a bitmap that is an inverted image of the passed in image. - // Each color becomes its inverse in the color wheel. So (255, 15, 0) becomes - // (0, 240, 255). The alpha value is not inverted. - static SkBitmap CreateInvertedBitmap(const SkBitmap& image); - - // Create a bitmap that is a superimposition of the second bitmap on top of - // the first. The provided bitmaps must use have the kARGB_8888_Config config - // and be of equal dimensions. - static SkBitmap CreateSuperimposedBitmap(const SkBitmap& first, - const SkBitmap& second); - - // Create a bitmap that is a blend of two others. The alpha argument - // specifies the opacity of the second bitmap. The provided bitmaps must - // use have the kARGB_8888_Config config and be of equal dimensions. - static SkBitmap CreateBlendedBitmap(const SkBitmap& first, - const SkBitmap& second, - double alpha); - - // Create a bitmap that is the original bitmap masked out by the mask defined - // in the alpha bitmap. The images must use the kARGB_8888_Config config and - // be of equal dimensions. - static SkBitmap CreateMaskedBitmap(const SkBitmap& first, - const SkBitmap& alpha); - - // We create a button background image by compositing the color and image - // together, then applying the mask. This is a highly specialized composite - // operation that is the equivalent of drawing a background in |color|, - // tiling |image| over the top, and then masking the result out with |mask|. - // The images must use kARGB_8888_Config config. - static SkBitmap CreateButtonBackground(SkColor color, - const SkBitmap& image, - const SkBitmap& mask); - - // Shift a bitmap's HSL values. The shift values are in the range of 0-1, - // with the option to specify -1 for 'no change'. The shift values are - // defined as: - // hsl_shift[0] (hue): The absolute hue value for the image - 0 and 1 map - // to 0 and 360 on the hue color wheel (red). - // hsl_shift[1] (saturation): A saturation shift for the image, with the - // following key values: - // 0 = remove all color. - // 0.5 = leave unchanged. - // 1 = fully saturate the image. - // hsl_shift[2] (lightness): A lightness shift for the image, with the - // following key values: - // 0 = remove all lightness (make all pixels black). - // 0.5 = leave unchanged. - // 1 = full lightness (make all pixels white). - static SkBitmap CreateHSLShiftedBitmap(const SkBitmap& bitmap, - color_utils::HSL hsl_shift); - - // Create a bitmap that is cropped from another bitmap. This is special - // because it tiles the original bitmap, so your coordinates can extend - // outside the bounds of the original image. - static SkBitmap CreateTiledBitmap(const SkBitmap& bitmap, - int src_x, int src_y, - int dst_w, int dst_h); - - // Iteratively downsamples by 2 until the bitmap is no smaller than the - // input size. The normal use of this is to downsample the bitmap "close" to - // the final size, and then use traditional resampling on the result. - // Because the bitmap will be closer to the final size, it will be faster, - // and linear interpolation will generally work well as a second step. - static SkBitmap DownsampleByTwoUntilSize(const SkBitmap& bitmap, - int min_w, int min_h); - - // Makes a bitmap half has large in each direction by averaging groups of - // 4 pixels. This is one step in generating a mipmap. - static SkBitmap DownsampleByTwo(const SkBitmap& bitmap); - - // Unpremultiplies all pixels in |bitmap|. You almost never want to call - // this, as |SkBitmap|s are always premultiplied by conversion. Call this - // only if you will pass the bitmap's data into a system function that - // doesn't expect premultiplied colors. - static SkBitmap UnPreMultiply(const SkBitmap& bitmap); - - // Transpose the pixels in |bitmap| by swapping x and y. - static SkBitmap CreateTransposedBtmap(const SkBitmap& bitmap); - - private: - SkBitmapOperations(); // Class for scoping only. - - FRIEND_TEST_ALL_PREFIXES(SkBitmapOperationsTest, DownsampleByTwo); - FRIEND_TEST_ALL_PREFIXES(SkBitmapOperationsTest, DownsampleByTwoSmall); -}; +#include "ui/gfx/skbitmap_operations.h" +// TODO(sail): remove this file once all includes have been updated. #endif // GFX_SKBITMAP_OPERATIONS_H_ diff --git a/gfx/skia_util.h b/gfx/skia_util.h index 00a1d1c..1af4255 100644 --- a/gfx/skia_util.h +++ b/gfx/skia_util.h @@ -6,34 +6,7 @@ #define GFX_SKIA_UTIL_H_ #pragma once -#include "third_party/skia/include/core/SkColor.h" -#include "third_party/skia/include/core/SkRect.h" - -class SkBitmap; -class SkShader; - -namespace gfx { - -class Rect; - -// Convert between Skia and gfx rect types. -SkRect RectToSkRect(const gfx::Rect& rect); -gfx::Rect SkRectToRect(const SkRect& rect); - -// Creates a vertical gradient shader. The caller owns the shader. -// Example usage to avoid leaks: -// SkSafeUnref(paint.setShader(gfx::CreateGradientShader(0, 10, red, blue))); -// -// (The old shader in the paint, if any, needs to be freed, and SkSafeUnref will -// handle the NULL case.) -SkShader* CreateGradientShader(int start_point, - int end_point, - SkColor start_color, - SkColor end_color); - -// Returns true if the two bitmaps contain the same pixels. -bool BitmapsAreEqual(const SkBitmap& bitmap1, const SkBitmap& bitmap2); - -} // namespace gfx; +#include "ui/gfx/skia_util.h" +// TODO(sail): remove this file once all includes have been updated. #endif // GFX_SKIA_UTIL_H_ diff --git a/gfx/skia_utils_gtk.h b/gfx/skia_utils_gtk.h index 1114908..f958340 100644 --- a/gfx/skia_utils_gtk.h +++ b/gfx/skia_utils_gtk.h @@ -6,18 +6,7 @@ #define APP_GFX_SKIA_UTILS_GTK_H_ #pragma once -#include "third_party/skia/include/core/SkColor.h" - -typedef struct _GdkColor GdkColor; - -namespace gfx { - -// Converts GdkColors to the ARGB layout Skia expects. -SkColor GdkColorToSkColor(GdkColor color); - -// Converts ARGB to GdkColor. -GdkColor SkColorToGdkColor(SkColor color); - -} // namespace gfx +#include "ui/gfx/skia_utils_gtk.h" +// TODO(sail): remove this file once all includes have been updated. #endif // APP_GFX_SKIA_UTILS_GTK_H_ diff --git a/gfx/test_suite.h b/gfx/test_suite.h index 7c6ffbd..97c6a8f 100644 --- a/gfx/test_suite.h +++ b/gfx/test_suite.h @@ -6,19 +6,7 @@ #define GFX_TEST_SUITE_H_ #pragma once -#include <string> - -#include "base/test/test_suite.h" -#include "build/build_config.h" - -class GfxTestSuite : public base::TestSuite { - public: - GfxTestSuite(int argc, char** argv); - - protected: - // Overridden from base::TestSuite: - virtual void Initialize(); - virtual void Shutdown(); -}; +#include "ui/gfx/test_suite.h" +// TODO(sail): remove this file once all includes have been updated. #endif // GFX_TEST_SUITE_H_ diff --git a/gfx/win_util.h b/gfx/win_util.h index 3daa00f..fc5cc0f 100644 --- a/gfx/win_util.h +++ b/gfx/win_util.h @@ -6,15 +6,8 @@ #define GFX_WIN_UTIL_H_ #pragma once -namespace gfx { - -// Returns true if Direct2d is available, false otherwise. -bool Direct2dIsAvailable(); - -// Returns true if DirectWrite is available, false otherwise. -bool DirectWriteIsAvailable(); - -} // namespace gfx; +#include "ui/gfx/win_util.h" +// TODO(sail): remove this file once all includes have been updated. #endif // GFX_WIN_UTIL_H_ diff --git a/gpu/gpu.gyp b/gpu/gpu.gyp index 6bb7ace..f2aee51 100644 --- a/gpu/gpu.gyp +++ b/gpu/gpu.gyp @@ -151,7 +151,7 @@ 'command_buffer_common', '../app/app.gyp:app_base', '../base/base.gyp:base', - '../gfx/gfx.gyp:gfx', + '../ui/gfx/gfx.gyp:gfx', '../third_party/angle/src/build_angle.gyp:translator_glsl', ], 'sources': [ diff --git a/media/tools/mfdecoder/README.chromium b/media/tools/mfdecoder/README.chromium index c946a54..422161d 100644 --- a/media/tools/mfdecoder/README.chromium +++ b/media/tools/mfdecoder/README.chromium @@ -9,7 +9,7 @@ The decoding can be done with or without hardware acceleration. If decoding is done without hardware acceleration, then the YV12 frames are converted into RGB using ConvertYUVToRGB32() provided in media/base/yuv_convert.h. They are then drawn to a window using StretchDIBits() -provided in gfx/gdi_util.h. +provided in ui/gfx/gdi_util.h. If decoding is done with hardware acceleration, then the frames are obtained from a D3D surface (IDirect3DSurface9). It is then drawn through calling @@ -43,4 +43,4 @@ flags: WARNING: Using both -h and -f, or opening too many windows with -h may lead to driver crash / system instability. Realistically, you will never want to -do this unless you want to push the limits of the GPU ...
\ No newline at end of file +do this unless you want to push the limits of the GPU ... diff --git a/remoting/remoting.gyp b/remoting/remoting.gyp index b297172..88b75ce 100644 --- a/remoting/remoting.gyp +++ b/remoting/remoting.gyp @@ -113,7 +113,7 @@ 'target_name': 'chromoting_base', 'type': '<(library)', 'dependencies': [ - '../gfx/gfx.gyp:gfx', + '../ui/gfx/gfx.gyp:gfx', '../media/media.gyp:media', '../third_party/protobuf/protobuf.gyp:protobuf_lite', '../third_party/libvpx/libvpx.gyp:libvpx_include', @@ -445,7 +445,7 @@ '../base/base.gyp:base', '../base/base.gyp:base_i18n', '../base/base.gyp:test_support_base', - '../gfx/gfx.gyp:gfx', + '../ui/gfx/gfx.gyp:gfx', '../testing/gmock.gyp:gmock', '../testing/gtest.gyp:gtest', ], diff --git a/tools/grit/resource_ids b/tools/grit/resource_ids index cb54fc2..97e9ee7 100644 --- a/tools/grit/resource_ids +++ b/tools/grit/resource_ids @@ -112,7 +112,7 @@ "structures": [18000], }, - "gfx/gfx_resources.grd": { + "ui/gfx/gfx_resources.grd": { "includes": [18500], }, diff --git a/ui/base/ui_base.gypi b/ui/base/ui_base.gypi index 3822d25..71443f6 100644 --- a/ui/base/ui_base.gypi +++ b/ui/base/ui_base.gypi @@ -46,7 +46,7 @@ 'type': '<(library)', 'dependencies': [ '../base/base.gyp:base', - '../gfx/gfx.gyp:gfx', + '../ui/gfx/gfx.gyp:gfx', '../skia/skia.gyp:skia', '../third_party/icu/icu.gyp:icui18n', '../third_party/icu/icu.gyp:icuuc', diff --git a/ui/gfx/DEPS b/ui/gfx/DEPS new file mode 100644 index 0000000..548fe15 --- /dev/null +++ b/ui/gfx/DEPS @@ -0,0 +1,5 @@ +include_rules = [ + "+base", + "+grit/gfx_resources.h", + "+skia", +] diff --git a/gfx/blit.cc b/ui/gfx/blit.cc index 8853339..8853339 100644 --- a/gfx/blit.cc +++ b/ui/gfx/blit.cc diff --git a/ui/gfx/blit.h b/ui/gfx/blit.h new file mode 100644 index 0000000..d5b1b5e --- /dev/null +++ b/ui/gfx/blit.h @@ -0,0 +1,53 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_GFX_BLIT_H_ +#define UI_GFX_BLIT_H_ +#pragma once + +#include "gfx/native_widget_types.h" + +namespace skia { +class PlatformCanvas; +} // namespace skia + +namespace gfx { + +class Point; +class Rect; + +// Blits a rectangle from the source context into the destination context. +void BlitContextToContext(NativeDrawingContext dst_context, + const Rect& dst_rect, + NativeDrawingContext src_context, + const Point& src_origin); + +// Blits a rectangle from the source context into the destination canvas. +void BlitContextToCanvas(skia::PlatformCanvas *dst_canvas, + const Rect& dst_rect, + NativeDrawingContext src_context, + const Point& src_origin); + +// Blits a rectangle from the source canvas into the destination context. +void BlitCanvasToContext(NativeDrawingContext dst_context, + const Rect& dst_rect, + skia::PlatformCanvas *src_canvas, + const Point& src_origin); + +// Blits a rectangle from the source canvas into the destination canvas. +void BlitCanvasToCanvas(skia::PlatformCanvas *dst_canvas, + const Rect& dst_rect, + skia::PlatformCanvas *src_canvas, + const Point& src_origin); + +// Scrolls the given subset of the given canvas by the given amount. +// The canvas should not have a clip or a transform applied, since platforms +// may implement those operations differently. +void ScrollCanvas(skia::PlatformCanvas* canvas, + const Rect& clip, + const Point& amount); + +} // namespace gfx + +#endif // UI_GFX_BLIT_H_ diff --git a/gfx/blit_unittest.cc b/ui/gfx/blit_unittest.cc index cea3296..cea3296 100644 --- a/gfx/blit_unittest.cc +++ b/ui/gfx/blit_unittest.cc diff --git a/ui/gfx/brush.h b/ui/gfx/brush.h new file mode 100644 index 0000000..d6e92af --- /dev/null +++ b/ui/gfx/brush.h @@ -0,0 +1,24 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_GFX_BRUSH_H_ +#define UI_GFX_BRUSH_H_ +#pragma once + +namespace gfx { + +// An object that encapsulates a platform native brush. +// Subclasses handle memory management of the underlying native brush. +class Brush { + public: + Brush() {} + virtual ~Brush() {} + + private: + DISALLOW_COPY_AND_ASSIGN(Brush); +}; + +} // namespace gfx + +#endif // UI_GFX_BRUSH_H_ diff --git a/gfx/canvas.cc b/ui/gfx/canvas.cc index 28e6a8a..28e6a8a 100644 --- a/gfx/canvas.cc +++ b/ui/gfx/canvas.cc diff --git a/ui/gfx/canvas.h b/ui/gfx/canvas.h new file mode 100644 index 0000000..9517602 --- /dev/null +++ b/ui/gfx/canvas.h @@ -0,0 +1,238 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_GFX_CANVAS_H_ +#define UI_GFX_CANVAS_H_ +#pragma once + +#include <string> + +#include "base/string16.h" +#include "gfx/native_widget_types.h" +// TODO(beng): remove this include when we no longer depend on SkTypes. +#include "skia/ext/platform_canvas.h" + +namespace gfx { + +class Brush; +class CanvasSkia; +class Font; +class Point; +class Rect; + +// TODO(beng): documentation. +class Canvas { + public: + // Specifies the alignment for text rendered with the DrawStringInt method. + enum { + TEXT_ALIGN_LEFT = 1, + TEXT_ALIGN_CENTER = 2, + TEXT_ALIGN_RIGHT = 4, + TEXT_VALIGN_TOP = 8, + TEXT_VALIGN_MIDDLE = 16, + TEXT_VALIGN_BOTTOM = 32, + + // Specifies the text consists of multiple lines. + MULTI_LINE = 64, + + // By default DrawStringInt does not process the prefix ('&') character + // specially. That is, the string "&foo" is rendered as "&foo". When + // rendering text from a resource that uses the prefix character for + // mnemonics, the prefix should be processed and can be rendered as an + // underline (SHOW_PREFIX), or not rendered at all (HIDE_PREFIX). + SHOW_PREFIX = 128, + HIDE_PREFIX = 256, + + // Prevent ellipsizing + NO_ELLIPSIS = 512, + + // Specifies if words can be split by new lines. + // This only works with MULTI_LINE. + CHARACTER_BREAK = 1024, + + // Instructs DrawStringInt() to render the text using RTL directionality. + // In most cases, passing this flag is not necessary because information + // about the text directionality is going to be embedded within the string + // in the form of special Unicode characters. However, we don't insert + // directionality characters into strings if the locale is LTR because some + // platforms (for example, an English Windows XP with no RTL fonts + // installed) don't support these characters. Thus, this flag should be + // used to render text using RTL directionality when the locale is LTR. + FORCE_RTL_DIRECTIONALITY = 2048, + }; + + virtual ~Canvas() {} + + // Creates an empty canvas. Must be initialized before it can be used. + static Canvas* CreateCanvas(); + + // Creates a canvas with the specified size. + static Canvas* CreateCanvas(int width, int height, bool is_opaque); + + // Saves a copy of the drawing state onto a stack, operating on this copy + // until a balanced call to Restore() is made. + virtual void Save() = 0; + + // As with Save(), except draws to a layer that is blended with the canvas + // at the specified alpha once Restore() is called. + // |layer_bounds| are the bounds of the layer relative to the current + // transform. + virtual void SaveLayerAlpha(uint8 alpha) = 0; + virtual void SaveLayerAlpha(uint8 alpha, const gfx::Rect& layer_bounds) = 0; + + // Restores the drawing state after a call to Save*(). It is an error to + // call Restore() more times than Save*(). + virtual void Restore() = 0; + + // Wrapper function that takes integer arguments. + // Returns true if the clip is non-empty. + // See clipRect for specifics. + virtual bool ClipRectInt(int x, int y, int w, int h) = 0; + + // Wrapper function that takes integer arguments. + // See translate() for specifics. + virtual void TranslateInt(int x, int y) = 0; + + // Wrapper function that takes integer arguments. + // See scale() for specifics. + virtual void ScaleInt(int x, int y) = 0; + + // Fills the specified region with the specified color using a transfer + // mode of SkXfermode::kSrcOver_Mode. + virtual void FillRectInt(const SkColor& color, + int x, int y, int w, int h) = 0; + + // Fills the specified region with the specified color and mode + virtual void FillRectInt(const SkColor& color, + int x, int y, int w, int h, + SkXfermode::Mode mode) = 0; + + // Fills the specified region with the specified brush. + virtual void FillRectInt(const gfx::Brush* brush, + int x, int y, int w, int h) = 0; + + // Draws a single pixel rect in the specified region with the specified + // color, using a transfer mode of SkXfermode::kSrcOver_Mode. + // + // NOTE: if you need a single pixel line, use DrawLineInt. + virtual void DrawRectInt(const SkColor& color, + int x, int y, int w, int h) = 0; + + // Draws a single pixel rect in the specified region with the specified + // color and transfer mode. + // + // NOTE: if you need a single pixel line, use DrawLineInt. + virtual void DrawRectInt(const SkColor& color, + int x, int y, int w, int h, + SkXfermode::Mode mode) = 0; + + // Draws the given rectangle with the given paint's parameters. + virtual void DrawRectInt(int x, int y, int w, int h, + const SkPaint& paint) = 0; + + // Draws a single pixel line with the specified color. + virtual void DrawLineInt(const SkColor& color, + int x1, int y1, + int x2, int y2) = 0; + + // Draws a bitmap with the origin at the specified location. The upper left + // corner of the bitmap is rendered at the specified location. + virtual void DrawBitmapInt(const SkBitmap& bitmap, int x, int y) = 0; + + // Draws a bitmap with the origin at the specified location, using the + // specified paint. The upper left corner of the bitmap is rendered at the + // specified location. + virtual void DrawBitmapInt(const SkBitmap& bitmap, + int x, int y, + const SkPaint& paint) = 0; + + // Draws a portion of a bitmap in the specified location. The src parameters + // correspond to the region of the bitmap to draw in the region defined + // by the dest coordinates. + // + // If the width or height of the source differs from that of the destination, + // the bitmap will be scaled. When scaling down, it is highly recommended + // that you call buildMipMap(false) on your bitmap to ensure that it has + // a mipmap, which will result in much higher-quality output. Set |filter| + // to use filtering for bitmaps, otherwise the nearest-neighbor algorithm + // is used for resampling. + // + // An optional custom SkPaint can be provided. + virtual void DrawBitmapInt(const SkBitmap& bitmap, + int src_x, int src_y, int src_w, int src_h, + int dest_x, int dest_y, int dest_w, int dest_h, + bool filter) = 0; + virtual void DrawBitmapInt(const SkBitmap& bitmap, + int src_x, int src_y, int src_w, int src_h, + int dest_x, int dest_y, int dest_w, int dest_h, + bool filter, + const SkPaint& paint) = 0; + + // Draws text with the specified color, font and location. The text is + // aligned to the left, vertically centered, clipped to the region. If the + // text is too big, it is truncated and '...' is added to the end. + virtual void DrawStringInt(const string16& text, const + gfx::Font& font, + const SkColor& color, + int x, int y, int w, int h) = 0; + virtual void DrawStringInt(const string16& text, + const gfx::Font& font, + const SkColor& color, + const gfx::Rect& display_rect) = 0; + + // Draws text with the specified color, font and location. The last argument + // specifies flags for how the text should be rendered. It can be one of + // TEXT_ALIGN_CENTER, TEXT_ALIGN_RIGHT or TEXT_ALIGN_LEFT. + virtual void DrawStringInt(const string16& text, + const gfx::Font& font, + const SkColor& color, + int x, int y, int w, int h, + int flags) = 0; + + // Draws a dotted gray rectangle used for focus purposes. + virtual void DrawFocusRect(int x, int y, int width, int height) = 0; + + // Tiles the image in the specified region. + virtual void TileImageInt(const SkBitmap& bitmap, + int x, int y, int w, int h) = 0; + virtual void TileImageInt(const SkBitmap& bitmap, + int src_x, int src_y, + int dest_x, int dest_y, int w, int h) = 0; + + // Returns a native drawing context for platform specific drawing routines to + // use. Must be balanced by a call to EndPlatformPaint(). + virtual gfx::NativeDrawingContext BeginPlatformPaint() = 0; + + // Signifies the end of platform drawing using the native drawing context + // returned by BeginPlatformPaint(). + virtual void EndPlatformPaint() = 0; + + // TODO(beng): remove this once we don't need to use any skia-specific methods + // through this interface. + // A quick and dirty way to obtain the underlying SkCanvas. + virtual CanvasSkia* AsCanvasSkia(); + virtual const CanvasSkia* AsCanvasSkia() const; +}; + +class CanvasPaint { + public: + virtual ~CanvasPaint() {} + + // Creates a canvas that paints to |view| when it is destroyed. The canvas is + // sized to the client area of |view|. + static CanvasPaint* CreateCanvasPaint(gfx::NativeView view); + + // Returns true if the canvas has an invalid rect that needs to be repainted. + virtual bool IsValid() const = 0; + + // Returns the rectangle that is invalid. + virtual gfx::Rect GetInvalidRect() const = 0; + + // Returns the underlying Canvas. + virtual Canvas* AsCanvas() = 0; +}; + +} // namespace gfx; + +#endif // UI_GFX_CANVAS_H_ diff --git a/gfx/canvas_direct2d.cc b/ui/gfx/canvas_direct2d.cc index cba7b64..cba7b64 100644 --- a/gfx/canvas_direct2d.cc +++ b/ui/gfx/canvas_direct2d.cc diff --git a/ui/gfx/canvas_direct2d.h b/ui/gfx/canvas_direct2d.h new file mode 100644 index 0000000..101688a --- /dev/null +++ b/ui/gfx/canvas_direct2d.h @@ -0,0 +1,112 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_GFX_CANVAS_DIRECT2D_H_ +#define UI_GFX_CANVAS_DIRECT2D_H_ +#pragma once + +#include <d2d1.h> + +#include <stack> + +#include "base/scoped_comptr_win.h" +#include "gfx/canvas.h" + +namespace gfx { + +class CanvasDirect2D : public Canvas { + public: + // Creates an empty Canvas. + explicit CanvasDirect2D(ID2D1RenderTarget* rt); + virtual ~CanvasDirect2D(); + + // Retrieves the application's D2D1 Factory. + static ID2D1Factory* GetD2D1Factory(); + + // Overridden from Canvas: + virtual void Save(); + virtual void SaveLayerAlpha(uint8 alpha); + virtual void SaveLayerAlpha(uint8 alpha, const gfx::Rect& layer_bounds); + virtual void Restore(); + virtual bool ClipRectInt(int x, int y, int w, int h); + virtual void TranslateInt(int x, int y); + virtual void ScaleInt(int x, int y); + virtual void FillRectInt(const SkColor& color, int x, int y, int w, int h); + virtual void FillRectInt(const SkColor& color, int x, int y, int w, int h, + SkXfermode::Mode mode); + virtual void FillRectInt(const gfx::Brush* brush, int x, int y, int w, int h); + virtual void DrawRectInt(const SkColor& color, int x, int y, int w, int h); + virtual void DrawRectInt(const SkColor& color, + int x, int y, int w, int h, + SkXfermode::Mode mode); + virtual void DrawRectInt(int x, int y, int w, int h, const SkPaint& paint); + virtual void DrawLineInt(const SkColor& color, + int x1, int y1, + int x2, int y2); + virtual void DrawBitmapInt(const SkBitmap& bitmap, int x, int y); + virtual void DrawBitmapInt(const SkBitmap& bitmap, + int x, int y, + const SkPaint& paint); + virtual void DrawBitmapInt(const SkBitmap& bitmap, + int src_x, int src_y, int src_w, int src_h, + int dest_x, int dest_y, int dest_w, int dest_h, + bool filter); + virtual void DrawBitmapInt(const SkBitmap& bitmap, + int src_x, int src_y, int src_w, int src_h, + int dest_x, int dest_y, int dest_w, int dest_h, + bool filter, + const SkPaint& paint); + virtual void DrawStringInt(const string16& text, + const gfx::Font& font, + const SkColor& color, + int x, int y, int w, int h); + virtual void DrawStringInt(const string16& text, + const gfx::Font& font, + const SkColor& color, + const gfx::Rect& display_rect); + virtual void DrawStringInt(const string16& text, + const gfx::Font& font, + const SkColor& color, + int x, int y, int w, int h, + int flags); + virtual void DrawFocusRect(int x, int y, int width, int height); + virtual void TileImageInt(const SkBitmap& bitmap, int x, int y, int w, int h); + virtual void TileImageInt(const SkBitmap& bitmap, + int src_x, int src_y, + int dest_x, int dest_y, int w, int h); + virtual gfx::NativeDrawingContext BeginPlatformPaint(); + virtual void EndPlatformPaint(); + virtual CanvasSkia* AsCanvasSkia(); + virtual const CanvasSkia* AsCanvasSkia() const; + + private: + void SaveInternal(ID2D1Layer* layer); + + ID2D1RenderTarget* rt_; + ScopedComPtr<ID2D1GdiInteropRenderTarget> interop_rt_; + ScopedComPtr<ID2D1DrawingStateBlock> drawing_state_block_; + static ID2D1Factory* d2d1_factory_; + + // Every time Save* is called, a RenderState object is pushed onto the + // RenderState stack. + struct RenderState { + explicit RenderState(ID2D1Layer* layer) : layer(layer), clip_count(0) {} + RenderState() : layer(NULL), clip_count(0) {} + + // A D2D layer associated with this state, or NULL if there is no layer. + // The layer is created and owned by the Canvas. + ID2D1Layer* layer; + // The number of clip operations performed. This is used to balance calls to + // PushAxisAlignedClip with calls to PopAxisAlignedClip when Restore() is + // called. + int clip_count; + }; + std::stack<RenderState> state_; + + DISALLOW_COPY_AND_ASSIGN(CanvasDirect2D); +}; + +} // namespace gfx; + +#endif // UI_GFX_CANVAS_DIRECT2D_H_ diff --git a/gfx/canvas_direct2d_unittest.cc b/ui/gfx/canvas_direct2d_unittest.cc index 8884f32..8884f32 100644 --- a/gfx/canvas_direct2d_unittest.cc +++ b/ui/gfx/canvas_direct2d_unittest.cc diff --git a/gfx/canvas_skia.cc b/ui/gfx/canvas_skia.cc index aa0cb9d..aa0cb9d 100644 --- a/gfx/canvas_skia.cc +++ b/ui/gfx/canvas_skia.cc diff --git a/ui/gfx/canvas_skia.h b/ui/gfx/canvas_skia.h new file mode 100644 index 0000000..ce16fae --- /dev/null +++ b/ui/gfx/canvas_skia.h @@ -0,0 +1,165 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_GFX_CANVAS_SKIA_H_ +#define UI_GFX_CANVAS_SKIA_H_ +#pragma once + +#include "base/basictypes.h" +#include "base/string16.h" +#include "gfx/canvas.h" +#include "skia/ext/platform_canvas.h" + +#if defined(OS_POSIX) && !defined(OS_MACOSX) +typedef struct _GdkPixbuf GdkPixbuf; +#endif + +namespace gfx { + +class Canvas; + +// CanvasSkia is a SkCanvas subclass that provides a number of methods for +// common operations used throughout an application built using base/gfx and +// app/gfx. +// +// All methods that take integer arguments (as is used throughout views) +// end with Int. If you need to use methods provided by the superclass +// you'll need to do a conversion. In particular you'll need to use +// macro SkIntToScalar(xxx), or if converting from a scalar to an integer +// SkScalarRound. +// +// A handful of methods in this class are overloaded providing an additional +// argument of type SkXfermode::Mode. SkXfermode::Mode specifies how the +// source and destination colors are combined. Unless otherwise specified, +// the variant that does not take a SkXfermode::Mode uses a transfer mode +// of kSrcOver_Mode. +class CanvasSkia : public skia::PlatformCanvas, + public Canvas { + public: + // Creates an empty Canvas. Callers must use initialize before using the + // canvas. + CanvasSkia(); + + CanvasSkia(int width, int height, bool is_opaque); + + virtual ~CanvasSkia(); + + // Compute the size required to draw some text with the provided font. + // Attempts to fit the text with the provided width and height. Increases + // height and then width as needed to make the text fit. This method + // supports multiple lines. + static void SizeStringInt(const string16& text, + const gfx::Font& font, + int* width, int* height, + int flags); + + // Returns the default text alignment to be used when drawing text on a + // gfx::CanvasSkia based on the directionality of the system locale language. + // This function is used by gfx::Canvas::DrawStringInt when the text alignment + // is not specified. + // + // This function returns either gfx::Canvas::TEXT_ALIGN_LEFT or + // gfx::Canvas::TEXT_ALIGN_RIGHT. + static int DefaultCanvasTextAlignment(); + +#if defined(OS_POSIX) && !defined(OS_MACOSX) + // Draw the pixbuf in its natural size at (x, y). + void DrawGdkPixbuf(GdkPixbuf* pixbuf, int x, int y); +#endif + +#if defined(OS_WIN) || (defined(OS_POSIX) && !defined(OS_MACOSX)) + // Draws text with a 1-pixel halo around it of the given color. + // On Windows, 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. + // On Linux, text with halo is created by stroking it with 2px |halo_color| + // then filling it with |text_color|. + void DrawStringWithHalo(const string16& text, + const gfx::Font& font, + const SkColor& text_color, + const SkColor& halo_color, + int x, int y, int w, int h, + int flags); +#endif + + // Extracts a bitmap from the contents of this canvas. + SkBitmap ExtractBitmap() const; + + // Overridden from Canvas: + virtual void Save(); + virtual void SaveLayerAlpha(uint8 alpha); + virtual void SaveLayerAlpha(uint8 alpha, const gfx::Rect& layer_bounds); + virtual void Restore(); + virtual bool ClipRectInt(int x, int y, int w, int h); + virtual void TranslateInt(int x, int y); + virtual void ScaleInt(int x, int y); + virtual void FillRectInt(const SkColor& color, int x, int y, int w, int h); + virtual void FillRectInt(const SkColor& color, int x, int y, int w, int h, + SkXfermode::Mode mode); + virtual void FillRectInt(const gfx::Brush* brush, int x, int y, int w, int h); + virtual void DrawRectInt(const SkColor& color, int x, int y, int w, int h); + virtual void DrawRectInt(const SkColor& color, + int x, int y, int w, int h, + SkXfermode::Mode mode); + virtual void DrawRectInt(int x, int y, int w, int h, const SkPaint& paint); + virtual void DrawLineInt(const SkColor& color, + int x1, int y1, + int x2, int y2); + virtual void DrawBitmapInt(const SkBitmap& bitmap, int x, int y); + virtual void DrawBitmapInt(const SkBitmap& bitmap, + int x, int y, + const SkPaint& paint); + virtual void DrawBitmapInt(const SkBitmap& bitmap, + int src_x, int src_y, int src_w, int src_h, + int dest_x, int dest_y, int dest_w, int dest_h, + bool filter); + virtual void DrawBitmapInt(const SkBitmap& bitmap, + int src_x, int src_y, int src_w, int src_h, + int dest_x, int dest_y, int dest_w, int dest_h, + bool filter, + const SkPaint& paint); + virtual void DrawStringInt(const string16& text, + const gfx::Font& font, + const SkColor& color, + int x, int y, int w, int h); + virtual void DrawStringInt(const string16& text, + const gfx::Font& font, + const SkColor& color, + const gfx::Rect& display_rect); + virtual void DrawStringInt(const string16& text, + const gfx::Font& font, + const SkColor& color, + int x, int y, int w, int h, + int flags); + virtual void DrawFocusRect(int x, int y, int width, int height); + virtual void TileImageInt(const SkBitmap& bitmap, int x, int y, int w, int h); + virtual void TileImageInt(const SkBitmap& bitmap, + int src_x, int src_y, + int dest_x, int dest_y, int w, int h); + virtual gfx::NativeDrawingContext BeginPlatformPaint(); + virtual void EndPlatformPaint(); + virtual CanvasSkia* AsCanvasSkia(); + virtual const CanvasSkia* AsCanvasSkia() const; + + private: + // Test whether the provided rectangle intersects the current clip rect. + bool IntersectsClipRectInt(int x, int y, int w, int h); + +#if defined(OS_WIN) + // Draws text with the specified color, font and location. The text is + // aligned to the left, vertically centered, clipped to the region. If the + // text is too big, it is truncated and '...' is added to the end. + void DrawStringInt(const string16& text, + HFONT font, + const SkColor& color, + int x, int y, int w, int h, + int flags); +#endif + + DISALLOW_COPY_AND_ASSIGN(CanvasSkia); +}; + +} // namespace gfx; + +#endif // UI_GFX_CANVAS_SKIA_H_ diff --git a/gfx/canvas_skia_linux.cc b/ui/gfx/canvas_skia_linux.cc index ce2ae01..ce2ae01 100644 --- a/gfx/canvas_skia_linux.cc +++ b/ui/gfx/canvas_skia_linux.cc diff --git a/gfx/canvas_skia_mac.mm b/ui/gfx/canvas_skia_mac.mm index fb30055..fb30055 100644 --- a/gfx/canvas_skia_mac.mm +++ b/ui/gfx/canvas_skia_mac.mm diff --git a/ui/gfx/canvas_skia_paint.h b/ui/gfx/canvas_skia_paint.h new file mode 100644 index 0000000..6ad854a --- /dev/null +++ b/ui/gfx/canvas_skia_paint.h @@ -0,0 +1,21 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_GFX_CANVAS_SKIA_PAINT_H_ +#define UI_GFX_CANVAS_SKIA_PAINT_H_ +#pragma once + +#include "gfx/canvas_skia.h" +#include "skia/ext/canvas_paint.h" + +// Define a gfx::CanvasSkiaPaint type that wraps our gfx::Canvas like the +// skia::PlatformCanvasPaint wraps PlatformCanvas. + +namespace gfx { + +typedef skia::CanvasPaintT<CanvasSkia> CanvasSkiaPaint; + +} // namespace gfx + +#endif // UI_GFX_CANVAS_SKIA_PAINT_H_ diff --git a/gfx/canvas_skia_win.cc b/ui/gfx/canvas_skia_win.cc index 03186fa..03186fa 100644 --- a/gfx/canvas_skia_win.cc +++ b/ui/gfx/canvas_skia_win.cc diff --git a/gfx/codec/DEPS b/ui/gfx/codec/DEPS index e4907a6c..e4907a6c 100644 --- a/gfx/codec/DEPS +++ b/ui/gfx/codec/DEPS diff --git a/gfx/codec/jpeg_codec.cc b/ui/gfx/codec/jpeg_codec.cc index ad499e5..ad499e5 100644 --- a/gfx/codec/jpeg_codec.cc +++ b/ui/gfx/codec/jpeg_codec.cc diff --git a/ui/gfx/codec/jpeg_codec.h b/ui/gfx/codec/jpeg_codec.h new file mode 100644 index 0000000..5ad4a4a8 --- /dev/null +++ b/ui/gfx/codec/jpeg_codec.h @@ -0,0 +1,68 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_GFX_CODEC_JPEG_CODEC_H_ +#define UI_GFX_CODEC_JPEG_CODEC_H_ +#pragma once + +#include <vector> + +class SkBitmap; + +namespace gfx { + +// Interface for encoding/decoding JPEG data. This is a wrapper around libjpeg, +// which has an inconvenient interface for callers. This is only used for UI +// elements, WebKit has its own more complicated JPEG decoder which handles, +// among other things, partially downloaded data. +class JPEGCodec { + public: + enum ColorFormat { + // 3 bytes per pixel (packed), in RGB order regardless of endianness. + // This is the native JPEG format. + FORMAT_RGB, + + // 4 bytes per pixel, in RGBA order in mem regardless of endianness. + FORMAT_RGBA, + + // 4 bytes per pixel, in BGRA order in mem regardless of endianness. + // This is the default Windows DIB order. + FORMAT_BGRA, + + // 4 bytes per pixel, it can be either RGBA or BGRA. It depends on the bit + // order in kARGB_8888_Config skia bitmap. + FORMAT_SkBitmap + }; + + // Encodes the given raw 'input' data, with each pixel being represented as + // given in 'format'. The encoded JPEG data will be written into the supplied + // vector and true will be returned on success. On failure (false), the + // contents of the output buffer are undefined. + // + // w, h: dimensions of the image + // row_byte_width: the width in bytes of each row. This may be greater than + // w * bytes_per_pixel if there is extra padding at the end of each row + // (often, each row is padded to the next machine word). + // quality: an integer in the range 0-100, where 100 is the highest quality. + static bool Encode(const unsigned char* input, ColorFormat format, + int w, int h, int row_byte_width, + int quality, std::vector<unsigned char>* output); + + // Decodes the JPEG data contained in input of length input_size. The + // decoded data will be placed in *output with the dimensions in *w and *h + // on success (returns true). This data will be written in the'format' + // format. On failure, the values of these output variables is undefined. + static bool Decode(const unsigned char* input, size_t input_size, + ColorFormat format, std::vector<unsigned char>* output, + int* w, int* h); + + // Decodes the JPEG data contained in input of length input_size. If + // successful, a SkBitmap is created and returned. It is up to the caller + // to delete the returned bitmap. + static SkBitmap* Decode(const unsigned char* input, size_t input_size); +}; + +} // namespace gfx + +#endif // UI_GFX_CODEC_JPEG_CODEC_H_ diff --git a/gfx/codec/jpeg_codec_unittest.cc b/ui/gfx/codec/jpeg_codec_unittest.cc index 16fc848..16fc848 100644 --- a/gfx/codec/jpeg_codec_unittest.cc +++ b/ui/gfx/codec/jpeg_codec_unittest.cc diff --git a/gfx/codec/png_codec.cc b/ui/gfx/codec/png_codec.cc index 5fd6d7a..5fd6d7a 100644 --- a/gfx/codec/png_codec.cc +++ b/ui/gfx/codec/png_codec.cc diff --git a/ui/gfx/codec/png_codec.h b/ui/gfx/codec/png_codec.h new file mode 100644 index 0000000..73453fe --- /dev/null +++ b/ui/gfx/codec/png_codec.h @@ -0,0 +1,105 @@ +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_GFX_CODEC_PNG_CODEC_H_ +#define UI_GFX_CODEC_PNG_CODEC_H_ +#pragma once + +#include <vector> + +#include "base/basictypes.h" + +class SkBitmap; + +namespace gfx { + +// Interface for encoding and decoding PNG data. This is a wrapper around +// libpng, which has an inconvenient interface for callers. This is currently +// designed for use in tests only (where we control the files), so the handling +// isn't as robust as would be required for a browser (see Decode() for more). +// WebKit has its own more complicated PNG decoder which handles, among other +// things, partially downloaded data. +class PNGCodec { + public: + enum ColorFormat { + // 3 bytes per pixel (packed), in RGB order regardless of endianness. + // This is the native JPEG format. + FORMAT_RGB, + + // 4 bytes per pixel, in RGBA order in memory regardless of endianness. + FORMAT_RGBA, + + // 4 bytes per pixel, in BGRA order in memory regardless of endianness. + // This is the default Windows DIB order. + FORMAT_BGRA, + + // 4 bytes per pixel, in pre-multiplied kARGB_8888_Config format. For use + // with directly writing to a skia bitmap. + FORMAT_SkBitmap + }; + + // Encodes the given raw 'input' data, with each pixel being represented as + // given in 'format'. The encoded PNG data will be written into the supplied + // vector and true will be returned on success. On failure (false), the + // contents of the output buffer are undefined. + // + // When writing alpha values, the input colors are assumed to be post + // multiplied. + // + // w, h: dimensions of the image + // row_byte_width: the width in bytes of each row. This may be greater than + // w * bytes_per_pixel if there is extra padding at the end of each row + // (often, each row is padded to the next machine word). + // discard_transparency: when true, and when the input data format includes + // alpha values, these alpha values will be discarded and only RGB will be + // written to the resulting file. Otherwise, alpha values in the input + // will be preserved. + static bool Encode(const unsigned char* input, ColorFormat format, + int w, int h, int row_byte_width, + bool discard_transparency, + std::vector<unsigned char>* output); + + // Call PNGCodec::Encode on the supplied SkBitmap |input|, which is assumed + // to be BGRA, 32 bits per pixel. The params |discard_transparency| and + // |output| are passed directly to Encode; refer to Encode for more + // information. During the call, an SkAutoLockPixels lock is held on |input|. + static bool EncodeBGRASkBitmap(const SkBitmap& input, + bool discard_transparency, + std::vector<unsigned char>* output); + + // Decodes the PNG data contained in input of length input_size. The + // decoded data will be placed in *output with the dimensions in *w and *h + // on success (returns true). This data will be written in the 'format' + // format. On failure, the values of these output variables are undefined. + // + // This function may not support all PNG types, and it hasn't been tested + // with a large number of images, so assume a new format may not work. It's + // really designed to be able to read in something written by Encode() above. + static bool Decode(const unsigned char* input, size_t input_size, + ColorFormat format, std::vector<unsigned char>* output, + int* w, int* h); + + // Decodes the PNG data directly into the passed in SkBitmap. This is + // significantly faster than the vector<unsigned char> version of Decode() + // above when dealing with PNG files that are >500K, which a lot of theme + // images are. (There are a lot of themes that have a NTP image of about ~1 + // megabyte, and those require a 7-10 megabyte side buffer.) + // + // Returns true if data is non-null and can be decoded as a png, false + // otherwise. + static bool Decode(const unsigned char* input, size_t input_size, + SkBitmap* bitmap); + + // Create a SkBitmap from a decoded BGRA DIB. The caller owns the returned + // SkBitmap. + static SkBitmap* CreateSkBitmapFromBGRAFormat( + std::vector<unsigned char>& bgra, int width, int height); + + private: + DISALLOW_COPY_AND_ASSIGN(PNGCodec); +}; + +} // namespace gfx + +#endif // UI_GFX_CODEC_PNG_CODEC_H_ diff --git a/gfx/codec/png_codec_unittest.cc b/ui/gfx/codec/png_codec_unittest.cc index 19d1f19..19d1f19 100644 --- a/gfx/codec/png_codec_unittest.cc +++ b/ui/gfx/codec/png_codec_unittest.cc diff --git a/gfx/color_utils.cc b/ui/gfx/color_utils.cc index 73c585b..73c585b 100644 --- a/gfx/color_utils.cc +++ b/ui/gfx/color_utils.cc diff --git a/ui/gfx/color_utils.h b/ui/gfx/color_utils.h new file mode 100644 index 0000000..a043b82 --- /dev/null +++ b/ui/gfx/color_utils.h @@ -0,0 +1,80 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_GFX_COLOR_UTILS_H_ +#define UI_GFX_COLOR_UTILS_H_ +#pragma once + +#include "third_party/skia/include/core/SkColor.h" + +class SkBitmap; + +namespace color_utils { + +// Represents an HSL color. +struct HSL { + double h; + double s; + double l; +}; + +// Calculated according to http://www.w3.org/TR/WCAG20/#relativeluminancedef +double RelativeLuminance(SkColor color); + +// Note: these transformations assume sRGB as the source color space +void SkColorToHSL(SkColor c, HSL* hsl); +SkColor HSLToSkColor(const HSL& hsl, SkAlpha alpha); + +// HSL-Shift an SkColor. The shift values are in the range of 0-1, with the +// option to specify -1 for 'no change'. The shift values are defined as: +// hsl_shift[0] (hue): The absolute hue value - 0 and 1 map +// to 0 and 360 on the hue color wheel (red). +// hsl_shift[1] (saturation): A saturation shift, with the +// following key values: +// 0 = remove all color. +// 0.5 = leave unchanged. +// 1 = fully saturate the image. +// hsl_shift[2] (lightness): A lightness shift, with the +// following key values: +// 0 = remove all lightness (make all pixels black). +// 0.5 = leave unchanged. +// 1 = full lightness (make all pixels white). +SkColor HSLShift(SkColor color, const HSL& shift); + +// Determine if a given alpha value is nearly completely transparent. +bool IsColorCloseToTransparent(SkAlpha alpha); + +// Determine if a color is near grey. +bool IsColorCloseToGrey(int r, int g, int b); + +// Gets a color representing a bitmap. The definition of "representing" is the +// average color in the bitmap. The color returned is modified to have the +// specified alpha. +SkColor GetAverageColorOfFavicon(SkBitmap* bitmap, SkAlpha alpha); + +// Builds a histogram based on the Y' of the Y'UV representation of +// this image. +void BuildLumaHistogram(SkBitmap* bitmap, int histogram[256]); + +// Returns a blend of the supplied colors, ranging from |background| (for +// |alpha| == 0) to |foreground| (for |alpha| == 255). The alpha channels of +// the supplied colors are also taken into account, so the returned color may +// be partially transparent. +SkColor AlphaBlend(SkColor foreground, SkColor background, SkAlpha alpha); + +// Given a foreground and background color, try to return a foreground color +// that is "readable" over the background color by luma-inverting the foreground +// color and then picking whichever foreground color has higher contrast against +// the background color. +// +// NOTE: This won't do anything but waste time if the supplied foreground color +// has a luma value close to the midpoint (0.5 in the HSL representation). +SkColor GetReadableColor(SkColor foreground, SkColor background); + +// Gets a Windows system color as a SkColor +SkColor GetSysSkColor(int which); + +} // namespace color_utils + +#endif // UI_GFX_COLOR_UTILS_H_ diff --git a/gfx/color_utils_unittest.cc b/ui/gfx/color_utils_unittest.cc index 30cf514..30cf514 100644 --- a/gfx/color_utils_unittest.cc +++ b/ui/gfx/color_utils_unittest.cc diff --git a/gfx/empty.cc b/ui/gfx/empty.cc index 63672f6..63672f6 100644 --- a/gfx/empty.cc +++ b/ui/gfx/empty.cc diff --git a/ui/gfx/favicon_size.h b/ui/gfx/favicon_size.h new file mode 100644 index 0000000..5e9cd55 --- /dev/null +++ b/ui/gfx/favicon_size.h @@ -0,0 +1,34 @@ +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_GFX_FAVICON_SIZE_H_ +#define UI_GFX_FAVICON_SIZE_H_ +#pragma once + +#include "base/compiler_specific.h" + +// Size (along each axis) of the favicon. +const int kFavIconSize = 16; + +// If the width or height is bigger than the favicon size, a new width/height +// is calculated and returned in width/height that maintains the aspect +// ratio of the supplied values. +static void calc_favicon_target_size(int* width, int* height) ALLOW_UNUSED; + +// static +void calc_favicon_target_size(int* width, int* height) { + if (*width > kFavIconSize || *height > kFavIconSize) { + // Too big, resize it maintaining the aspect ratio. + float aspect_ratio = static_cast<float>(*width) / + static_cast<float>(*height); + *height = kFavIconSize; + *width = static_cast<int>(aspect_ratio * *height); + if (*width > kFavIconSize) { + *width = kFavIconSize; + *height = static_cast<int>(*width / aspect_ratio); + } + } +} + +#endif // UI_GFX_FAVICON_SIZE_H_ diff --git a/gfx/font.cc b/ui/gfx/font.cc index 78b1a34..78b1a34 100644 --- a/gfx/font.cc +++ b/ui/gfx/font.cc diff --git a/ui/gfx/font.h b/ui/gfx/font.h new file mode 100644 index 0000000..2091ae3 --- /dev/null +++ b/ui/gfx/font.h @@ -0,0 +1,113 @@ +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_GFX_FONT_H_ +#define UI_GFX_FONT_H_ +#pragma once + +#include <string> + +#include "base/ref_counted.h" +#include "base/string16.h" +#include "gfx/native_widget_types.h" + +namespace gfx { + +class PlatformFont; + +// Font provides a wrapper around an underlying font. Copy and assignment +// operators are explicitly allowed, and cheap. +class Font { + public: + // The following constants indicate the font style. + enum FontStyle { + NORMAL = 0, + BOLD = 1, + ITALIC = 2, + UNDERLINED = 4, + }; + + // Creates a font with the default name and style. + Font(); + + // Creates a font that is a clone of another font object. + Font(const Font& other); + gfx::Font& operator=(const Font& other); + + // Creates a font from the specified native font. + explicit Font(NativeFont native_font); + + // Construct a Font object with the specified PlatformFont object. The Font + // object takes ownership of the PlatformFont object. + explicit Font(PlatformFont* platform_font); + + // Creates a font with the specified name and size. + Font(const string16& font_name, int font_size); + + ~Font(); + + // Returns a new Font derived from the existing font. + // size_deta is the size to add to the current font. For example, a value + // of 5 results in a font 5 units bigger than this font. + Font DeriveFont(int size_delta) const; + + // Returns a new Font derived from the existing font. + // size_delta is the size to add to the current font. See the single + // argument version of this method for an example. + // The style parameter specifies the new style for the font, and is a + // bitmask of the values: BOLD, ITALIC and UNDERLINED. + Font DeriveFont(int size_delta, int style) const; + + // Returns the number of vertical pixels needed to display characters from + // the specified font. This may include some leading, i.e. height may be + // greater than just ascent + descent. Specifically, the Windows and Mac + // implementations include leading and the Linux one does not. This may + // need to be revisited in the future. + int GetHeight() const; + + // Returns the baseline, or ascent, of the font. + int GetBaseline() const; + + // Returns the average character width for the font. + int GetAverageCharacterWidth() const; + + // Returns the number of horizontal pixels needed to display the specified + // string. + int GetStringWidth(const string16& text) const; + + // Returns the expected number of horizontal pixels needed to display the + // specified length of characters. Call GetStringWidth() to retrieve the + // actual number. + int GetExpectedTextWidth(int length) const; + + // Returns the style of the font. + int GetStyle() const; + + // Returns the font name. + string16 GetFontName() const; + + // Returns the font size in pixels. + int GetFontSize() const; + + // Returns the native font handle. + // Lifetime lore: + // Windows: This handle is owned by the Font object, and should not be + // destroyed by the caller. + // Mac: Caller must release this object. + // Gtk: This handle is created on demand, and must be freed by calling + // pango_font_description_free() when the caller is done using it. + NativeFont GetNativeFont() const; + + // Raw access to the underlying platform font implementation. Can be + // static_cast to a known implementation type if needed. + PlatformFont* platform_font() const { return platform_font_.get(); } + + private: + // Wrapped platform font implementation. + scoped_refptr<PlatformFont> platform_font_; +}; + +} // namespace gfx + +#endif // UI_GFX_FONT_H_ diff --git a/gfx/font_unittest.cc b/ui/gfx/font_unittest.cc index 43eaa7c..43eaa7c 100644 --- a/gfx/font_unittest.cc +++ b/ui/gfx/font_unittest.cc diff --git a/gfx/gdi_util.cc b/ui/gfx/gdi_util.cc index 5dbb5b5..5dbb5b5 100644 --- a/gfx/gdi_util.cc +++ b/ui/gfx/gdi_util.cc diff --git a/ui/gfx/gdi_util.h b/ui/gfx/gdi_util.h new file mode 100644 index 0000000..e79a34f --- /dev/null +++ b/ui/gfx/gdi_util.h @@ -0,0 +1,38 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_GFX_GDI_UTIL_H_ +#define UI_GFX_GDI_UTIL_H_ +#pragma once + +#include <vector> +#include <windows.h> + +#include "gfx/rect.h" + +namespace gfx { + +// Creates a BITMAPINFOHEADER structure given the bitmap's size. +void CreateBitmapHeader(int width, int height, BITMAPINFOHEADER* hdr); + +// Creates a BITMAPINFOHEADER structure given the bitmap's size and +// color depth in bits per pixel. +void CreateBitmapHeaderWithColorDepth(int width, int height, int color_depth, + BITMAPINFOHEADER* hdr); + +// Creates a BITMAPV4HEADER structure given the bitmap's size. You probably +// only need to use BMP V4 if you need transparency (alpha channel). This +// function sets the AlphaMask to 0xff000000. +void CreateBitmapV4Header(int width, int height, BITMAPV4HEADER* hdr); + +// Creates a monochrome bitmap header. +void CreateMonochromeBitmapHeader(int width, int height, BITMAPINFOHEADER* hdr); + +// Modify the given hrgn by subtracting the given rectangles. +void SubtractRectanglesFromRegion(HRGN hrgn, + const std::vector<gfx::Rect>& cutouts); + +} // namespace gfx + +#endif // UI_GFX_GDI_UTIL_H_ diff --git a/gfx/gfx.gyp b/ui/gfx/gfx.gyp index ac512f3..04df70d 100644 --- a/gfx/gfx.gyp +++ b/ui/gfx/gfx.gyp @@ -5,10 +5,10 @@ { 'variables': { 'chromium_code': 1, - 'grit_info_cmd': ['python', '../tools/grit/grit_info.py', + 'grit_info_cmd': ['python', '../../tools/grit/grit_info.py', '<@(grit_defines)'], - 'grit_cmd': ['python', '../tools/grit/grit.py'], - 'grit_out_dir': '<(SHARED_INTERMEDIATE_DIR)/gfx', + 'grit_cmd': ['python', '../../tools/grit/grit.py'], + 'grit_out_dir': '<(SHARED_INTERMEDIATE_DIR)/ui/gfx', }, 'targets': [ { @@ -18,9 +18,9 @@ 'dependencies': [ 'gfx', 'gfx_resources', - '../base/base.gyp:test_support_base', - '../skia/skia.gyp:skia', - '../testing/gtest.gyp:gtest', + '../../base/base.gyp:test_support_base', + '../../skia/skia.gyp:skia', + '../../testing/gtest.gyp:gtest', ], 'sources': [ 'blit_unittest.cc', @@ -35,10 +35,10 @@ 'skbitmap_operations_unittest.cc', 'test_suite.cc', 'test_suite.h', - '<(SHARED_INTERMEDIATE_DIR)/gfx/gfx_resources.rc', + '<(SHARED_INTERMEDIATE_DIR)/ui/gfx/gfx_resources.rc', ], 'include_dirs': [ - '..', + '../..', ], 'conditions': [ ['OS=="win"', { @@ -49,7 +49,7 @@ 'native_theme_win_unittest.cc', ], 'include_dirs': [ - '..', + '../..', '<(DEPTH)/third_party/wtl/include', ], 'msvs_settings': { @@ -67,7 +67,7 @@ }], ['OS=="linux" or OS=="freebsd" or OS=="openbsd"', { 'dependencies': [ - '../build/linux/system.gyp:gtk', + '../../build/linux/system.gyp:gtk', ], }], ], @@ -77,13 +77,13 @@ 'type': '<(library)', 'msvs_guid': '13A8D36C-0467-4B4E-BAA3-FD69C45F076A', 'dependencies': [ - '../base/base.gyp:base', - '../base/base.gyp:base_i18n', - '../skia/skia.gyp:skia', - '../third_party/icu/icu.gyp:icui18n', - '../third_party/icu/icu.gyp:icuuc', - '../third_party/libpng/libpng.gyp:libpng', - '../third_party/zlib/zlib.gyp:zlib', + '../../base/base.gyp:base', + '../../base/base.gyp:base_i18n', + '../../skia/skia.gyp:skia', + '../../third_party/icu/icu.gyp:icui18n', + '../../third_party/icu/icu.gyp:icuuc', + '../../third_party/libpng/libpng.gyp:libpng', + '../../third_party/zlib/zlib.gyp:zlib', 'gfx_resources', '<(libjpeg_gyp_path):libjpeg', ], @@ -158,7 +158,7 @@ 'win_util.h', ], 'include_dirs': [ - '..', + '../..', '<(DEPTH)/third_party/wtl/include', ], }], @@ -166,8 +166,8 @@ 'dependencies': [ # font_gtk.cc uses fontconfig. # TODO(evanm): I think this is wrong; it should just use GTK. - '../build/linux/system.gyp:fontconfig', - '../build/linux/system.gyp:gtk', + '../../build/linux/system.gyp:fontconfig', + '../../build/linux/system.gyp:gtk', ], 'sources': [ 'gtk_native_view_id_manager.cc', @@ -216,7 +216,7 @@ }, 'conditions': [ ['OS=="win"', { - 'dependencies': ['../build/win/system.gyp:cygwin'], + 'dependencies': ['../../build/win/system.gyp:cygwin'], }], ], }, diff --git a/gfx/gfx_module.cc b/ui/gfx/gfx_module.cc index 882efad..882efad 100644 --- a/gfx/gfx_module.cc +++ b/ui/gfx/gfx_module.cc diff --git a/ui/gfx/gfx_module.h b/ui/gfx/gfx_module.h new file mode 100644 index 0000000..0070eac --- /dev/null +++ b/ui/gfx/gfx_module.h @@ -0,0 +1,34 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_GFX_MODULE_H_ +#define UI_GFX_MODULE_H_ +#pragma once + +#include "base/basictypes.h" +#include "base/string_piece.h" + +namespace gfx { + +// Defines global initializers and associated methods for the gfx module. +// See net/base/net_module.h for more details. +class GfxModule { + public: + typedef base::StringPiece (*ResourceProvider)(int key); + + // Set the function to call when the gfx module needs resources + static void SetResourceProvider(ResourceProvider func); + + // Call the resource provider (if one exists) to get the specified resource. + // Returns an empty string if the resource does not exist or if there is no + // resource provider. + static base::StringPiece GetResource(int key); + + private: + DISALLOW_IMPLICIT_CONSTRUCTORS(GfxModule); +}; + +} // namespace gfx + +#endif // UI_GFX_MODULE_H_ diff --git a/gfx/gfx_paths.cc b/ui/gfx/gfx_paths.cc index bcb82ab..bcb82ab 100644 --- a/gfx/gfx_paths.cc +++ b/ui/gfx/gfx_paths.cc diff --git a/ui/gfx/gfx_paths.h b/ui/gfx/gfx_paths.h new file mode 100644 index 0000000..6be0cc3 --- /dev/null +++ b/ui/gfx/gfx_paths.h @@ -0,0 +1,28 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_GFX_GFX_PATHS_H_ +#define UI_GFX_GFX_PATHS_H_ +#pragma once + +// This file declares path keys for the app module. These can be used with +// the PathService to access various special directories and files. + +namespace gfx { + +enum { + PATH_START = 2000, + + // Valid only in development environment; TODO(darin): move these + DIR_TEST_DATA, // Directory where unit test data resides. + + PATH_END +}; + +// Call once to register the provider for the path keys defined above. +void RegisterPathProvider(); + +} // namespace gfx + +#endif // UI_GFX_GFX_PATHS_H_ diff --git a/gfx/gfx_resources.grd b/ui/gfx/gfx_resources.grd index 357679d..8b9b4b4 100644 --- a/gfx/gfx_resources.grd +++ b/ui/gfx/gfx_resources.grd @@ -7,6 +7,8 @@ <output filename="grit/gfx_resources_map.cc" type="resource_map_source" /> <output filename="grit/gfx_resources_map.h" type="resource_map_header" /> <output filename="gfx_resources.pak" type="data_package" /> + <!-- TODO(sail): remove this file once WebKit has been updated. --> + <output filename="../../gfx/gfx_resources.pak" type="data_package" /> <output filename="gfx_resources.rc" type="rc_all" /> </outputs> <release seq="1"> diff --git a/gfx/gtk_native_view_id_manager.cc b/ui/gfx/gtk_native_view_id_manager.cc index e9e72f2..e9e72f2 100644 --- a/gfx/gtk_native_view_id_manager.cc +++ b/ui/gfx/gtk_native_view_id_manager.cc diff --git a/ui/gfx/gtk_native_view_id_manager.h b/ui/gfx/gtk_native_view_id_manager.h new file mode 100644 index 0000000..6befcfc --- /dev/null +++ b/ui/gfx/gtk_native_view_id_manager.h @@ -0,0 +1,141 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_GFX_GTK_NATIVE_VIEW_ID_MANAGER_H_ +#define UI_GFX_GTK_NATIVE_VIEW_ID_MANAGER_H_ +#pragma once + +#include <map> + +#include "base/singleton.h" +#include "base/synchronization/lock.h" +#include "gfx/native_widget_types.h" + +typedef unsigned long XID; +struct _GtkPreserveWindow; + +// NativeViewIds are the opaque values which the renderer holds as a reference +// to a window. These ids are often used in sync calls from the renderer and +// one cannot terminate sync calls on the UI thread as that can lead to +// deadlocks. +// +// Because of this, we have the BACKGROUND_X11 thread for these calls and this +// thread has a separate X connection in order to answer them. But one cannot +// use GTK on multiple threads, so the BACKGROUND_X11 thread deals only in Xlib +// calls and, thus, XIDs. +// +// So we could make NativeViewIds be the X id of the window. However, at the +// time when we need to tell the renderer about its NativeViewId, an XID isn't +// availible and it goes very much against the grain of the code to make it so. +// Also, we worry that GTK might choose to change the underlying X window id +// when, say, the widget is hidden or repacked. Finally, if we used XIDs then a +// compromised renderer could start asking questions about any X windows on the +// system. +// +// Thus, we have this object. It produces random NativeViewIds from GtkWidget +// pointers and observes the various signals from the widget for when an X +// window is created, destroyed etc. Thus it provides a thread safe mapping +// from NativeViewIds to the current XID for that widget. +class GtkNativeViewManager { + public: + // Returns the singleton instance. + static GtkNativeViewManager* GetInstance(); + + // Must be called from the UI thread: + // + // Return a NativeViewId for the given widget and attach to the various + // signals emitted by that widget. The NativeViewId is pseudo-randomly + // allocated so that a compromised renderer trying to guess values will fail + // with high probability. The NativeViewId will not be reused for the + // lifetime of the GtkWidget. + gfx::NativeViewId GetIdForWidget(gfx::NativeView widget); + + // May be called from any thread: + // + // xid: (output) the resulting X window ID, or 0 + // id: a value previously returned from GetIdForWidget + // returns: true if |id| is a valid id, false otherwise. + // + // If the widget referenced by |id| does not current have an X window id, + // |*xid| is set to 0. + bool GetXIDForId(XID* xid, gfx::NativeViewId id); + + // Must be called from the UI thread because we may need the associated + // widget to create a window. + // + // Keeping the XID permanent requires a bit of overhead, so it must + // be explicitly requested. + // + // xid: (output) the resulting X window + // id: a value previously returned from GetIdForWidget + // returns: true if |id| is a valid id, false otherwise. + bool GetPermanentXIDForId(XID* xid, gfx::NativeViewId id); + + // Must be called from the UI thread because we may need to access a + // GtkWidget or destroy a GdkWindow. + // + // If the widget associated with the XID is still alive, allow the widget + // to destroy the associated XID when it wants. Otherwise, destroy the + // GdkWindow associated with the XID. + void ReleasePermanentXID(XID xid); + + // These are actually private functions, but need to be called from statics. + void OnRealize(gfx::NativeView widget); + void OnUnrealize(gfx::NativeView widget); + void OnDestroy(gfx::NativeView widget); + + base::Lock& unrealize_lock() { return unrealize_lock_; } + + private: + // This object is a singleton: + GtkNativeViewManager(); + ~GtkNativeViewManager(); + friend struct DefaultSingletonTraits<GtkNativeViewManager>; + + struct NativeViewInfo { + NativeViewInfo() : widget(NULL), x_window_id(0) { + } + gfx::NativeView widget; + XID x_window_id; + }; + + gfx::NativeViewId GetWidgetId(gfx::NativeView id); + + // This lock can be used to block GTK from unrealizing windows. This is needed + // when the BACKGROUND_X11 thread is using a window obtained via GetXIDForId, + // and can't allow the X11 resource to be deleted. + base::Lock unrealize_lock_; + + // protects native_view_to_id_ and id_to_info_ + base::Lock lock_; + + // If asked for an id for the same widget twice, we want to return the same + // id. So this records the current mapping. + std::map<gfx::NativeView, gfx::NativeViewId> native_view_to_id_; + std::map<gfx::NativeViewId, NativeViewInfo> id_to_info_; + + struct PermanentXIDInfo { + PermanentXIDInfo() : widget(NULL), ref_count(0) { + } + _GtkPreserveWindow* widget; + int ref_count; + }; + + // Used to maintain the reference count for permanent XIDs + // (referenced by GetPermanentXIDForId and dereferenced by + // ReleasePermanentXID). Only those XIDs with a positive reference count + // will be in the table. + // + // In general, several GTK widgets may share the same X window. We assume + // that is not true of the widgets stored in this registry. + // + // An XID will map to NULL, if there is an outstanding reference but the + // widget was destroyed. In this case, the destruction of the X window + // is deferred to the dropping of all references. + std::map<XID, PermanentXIDInfo> perm_xid_to_info_; + + DISALLOW_COPY_AND_ASSIGN(GtkNativeViewManager); +}; + +#endif // UI_GFX_GTK_NATIVE_VIEW_ID_MANAGER_H_ diff --git a/gfx/gtk_preserve_window.cc b/ui/gfx/gtk_preserve_window.cc index 20215d1..20215d1 100644 --- a/gfx/gtk_preserve_window.cc +++ b/ui/gfx/gtk_preserve_window.cc diff --git a/ui/gfx/gtk_preserve_window.h b/ui/gfx/gtk_preserve_window.h new file mode 100644 index 0000000..3c9b1d8 --- /dev/null +++ b/ui/gfx/gtk_preserve_window.h @@ -0,0 +1,64 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_GFX_GTK_PRESERVE_WINDOW_H_ +#define UI_GFX_GTK_PRESERVE_WINDOW_H_ +#pragma once + +#include <gdk/gdk.h> +#include <gtk/gtk.h> + +// GtkFixed creates an X window when realized and destroys an X window +// when unrealized. GtkPreserveWindow allows overrides this +// behaviour. When preserve is set (via gtk_preserve_window_set_preserve), +// the X window is only destroyed when the widget is destroyed. + +G_BEGIN_DECLS + +#define GTK_TYPE_PRESERVE_WINDOW \ + (gtk_preserve_window_get_type()) +#define GTK_PRESERVE_WINDOW(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj), GTK_TYPE_PERSERVE_WINDOW, \ + GtkPreserveWindow)) +#define GTK_PRESERVE_WINDOW_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass), GTK_TYPE_PRESERVE_WINDOW, \ + GtkPreserveWindowClass)) +#define GTK_IS_PRESERVE_WINDOW(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE((obj), GTK_TYPE_PRESERVE_WINDOW)) +#define GTK_IS_PRESERVE_WINDOW_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE((klass), GTK_TYPE_PRESERVE_WINDOW)) +#define GTK_PRESERVE_WINDOW_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS((obj), GTK_TYPE_PRESERVE_WINDOW, \ + GtkPreserveWindowClass)) + +typedef struct _GtkPreserveWindow GtkPreserveWindow; +typedef struct _GtkPreserveWindowClass GtkPreserveWindowClass; + +struct _GtkPreserveWindow { + // Parent class. + GtkFixed fixed; +}; + +struct _GtkPreserveWindowClass { + GtkFixedClass parent_class; +}; + +GType gtk_preserve_window_get_type() G_GNUC_CONST; +GtkWidget* gtk_preserve_window_new(); + +// Whether or not we should preserve associated windows as the widget +// is realized or unrealized. +gboolean gtk_preserve_window_get_preserve(GtkPreserveWindow* widget); +void gtk_preserve_window_set_preserve(GtkPreserveWindow* widget, + gboolean value); + +// Whether or not someone else will gdk_window_resize the GdkWindow associated +// with this widget (needed by the GPU process to synchronize resizing +// with swapped between front and back buffer). +void gtk_preserve_window_delegate_resize(GtkPreserveWindow* widget, + gboolean delegate); + +G_END_DECLS + +#endif // UI_GFX_GTK_PRESERVE_WINDOW_H_ diff --git a/gfx/gtk_util.cc b/ui/gfx/gtk_util.cc index fc240e0..fc240e0 100644 --- a/gfx/gtk_util.cc +++ b/ui/gfx/gtk_util.cc diff --git a/ui/gfx/gtk_util.h b/ui/gfx/gtk_util.h new file mode 100644 index 0000000..71cb792 --- /dev/null +++ b/ui/gfx/gtk_util.h @@ -0,0 +1,84 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_GFX_GTK_UTIL_H_ +#define UI_GFX_GTK_UTIL_H_ +#pragma once + +#include <glib-object.h> +#include <stdint.h> + +#include <string> +#include <vector> + +#include "base/scoped_ptr.h" + +typedef struct _GdkPixbuf GdkPixbuf; +typedef struct _GdkRegion GdkRegion; +typedef struct _GdkCursor GdkCursor; + +class CommandLine; +class SkBitmap; + +namespace gfx { + +class Rect; + +// Call gtk_init() using the argc and argv from command_line. +// gtk_init() wants an argc and argv that it can mutate; we provide those, +// but leave the original CommandLine unaltered. +void GtkInitFromCommandLine(const CommandLine& command_line); + +// Convert and copy a SkBitmap to a GdkPixbuf. NOTE: this uses BGRAToRGBA, so +// it is an expensive operation. The returned GdkPixbuf will have a refcount of +// 1, and the caller is responsible for unrefing it when done. +GdkPixbuf* GdkPixbufFromSkBitmap(const SkBitmap* bitmap); + +// Modify the given region by subtracting the given rectangles. +void SubtractRectanglesFromRegion(GdkRegion* region, + const std::vector<Rect>& cutouts); + +// Returns the resolution (DPI) used by pango. A negative values means the +// resolution hasn't been set. +double GetPangoResolution(); + +// Returns a static instance of a GdkCursor* object, sharable across the +// process. Caller must gdk_cursor_ref() it if they want to assume ownership. +GdkCursor* GetCursor(int type); + +// Change windows accelerator style to GTK style. (GTK uses _ for +// accelerators. Windows uses & with && as an escape for &.) +std::string ConvertAcceleratorsFromWindowsStyle(const std::string& label); + +// Removes the "&" accelerators from a Windows label. +std::string RemoveWindowsStyleAccelerators(const std::string& label); + +// Makes a copy of |pixels| with the ordering changed from BGRA to RGBA. +// The caller is responsible for free()ing the data. If |stride| is 0, it's +// assumed to be 4 * |width|. +uint8_t* BGRAToRGBA(const uint8_t* pixels, int width, int height, int stride); + +} // namespace gfx + +namespace { +// A helper class that will g_object_unref |p| when it goes out of scope. +// This never adds a ref, it only unrefs. +template <typename Type> +struct GObjectUnrefer { + void operator()(Type* ptr) const { + if (ptr) + g_object_unref(ptr); + } +}; +} // namespace + +// It's not legal C++ to have a templatized typedefs, so we wrap it in a +// struct. When using this, you need to include ::Type. E.g., +// ScopedGObject<GdkPixbufLoader>::Type loader(gdk_pixbuf_loader_new()); +template<class T> +struct ScopedGObject { + typedef scoped_ptr_malloc<T, GObjectUnrefer<T> > Type; +}; + +#endif // UI_GFX_GTK_UTIL_H_ diff --git a/gfx/icon_util.cc b/ui/gfx/icon_util.cc index cabc505..cabc505 100644 --- a/gfx/icon_util.cc +++ b/ui/gfx/icon_util.cc diff --git a/ui/gfx/icon_util.h b/ui/gfx/icon_util.h new file mode 100644 index 0000000..ae23601 --- /dev/null +++ b/ui/gfx/icon_util.h @@ -0,0 +1,194 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_GFX_ICON_UTIL_H_ +#define UI_GFX_ICON_UTIL_H_ +#pragma once + +#include <windows.h> +#include <string> +#include <vector> +#include "base/basictypes.h" + +namespace gfx { +class Size; +} +class FilePath; +class SkBitmap; + +/////////////////////////////////////////////////////////////////////////////// +// +// The IconUtil class contains helper functions for manipulating Windows icons. +// The class interface contains methods for converting an HICON handle into an +// SkBitmap object and vice versa. The class can also create a .ico file given +// a PNG image contained in an SkBitmap object. The following code snippet +// shows an example usage of IconUtil::CreateHICONFromSkBitmap(): +// +// SkBitmap bitmap; +// +// // Fill |bitmap| with valid data +// bitmap.setConfig(...); +// bitmap.allocPixels(); +// +// ... +// +// // Convert the bitmap into a Windows HICON +// HICON icon = IconUtil::CreateHICONFromSkBitmap(bitmap); +// if (icon == NULL) { +// // Handle error +// ... +// } +// +// // Use the icon with a WM_SETICON message +// ::SendMessage(hwnd, WM_SETICON, static_cast<WPARAM>(ICON_BIG), +// reinterpret_cast<LPARAM>(icon)); +// +// // Destroy the icon when we are done +// ::DestroyIcon(icon); +// +/////////////////////////////////////////////////////////////////////////////// +class IconUtil { + public: + // Given an SkBitmap object, the function converts the bitmap to a Windows + // icon and returns the corresponding HICON handle. If the function cannot + // convert the bitmap, NULL is returned. + // + // The client is responsible for destroying the icon when it is no longer + // needed by calling ::DestroyIcon(). + static HICON CreateHICONFromSkBitmap(const SkBitmap& bitmap); + + // Given a valid HICON handle representing an icon, this function converts + // the icon into an SkBitmap object containing an ARGB bitmap using the + // dimensions specified in |s|. |s| must specify valid dimensions (both + // width() an height() must be greater than zero). If the function cannot + // convert the icon to a bitmap (most probably due to an invalid parameter), + // the return value is NULL. + // + // The client owns the returned bitmap object and is responsible for deleting + // it when it is no longer needed. + static SkBitmap* CreateSkBitmapFromHICON(HICON icon, const gfx::Size& s); + + // Given an initialized SkBitmap object and a file name, this function + // creates a .ico file with the given name using the provided bitmap. The + // icon file is created with multiple icon images of varying predefined + // dimensions because Windows uses different image sizes when loading icons, + // depending on where the icon is drawn (ALT+TAB window, desktop shortcut, + // Quick Launch, etc.). |icon_file_name| needs to specify the full path for + // the desired .ico file. + // + // The function returns true on success and false otherwise. + static bool CreateIconFileFromSkBitmap(const SkBitmap& bitmap, + const FilePath& icon_path); + + private: + // The icon format is published in the MSDN but there is no definition of + // the icon file structures in any of the Windows header files so we need to + // define these structure within the class. We must make sure we use 2 byte + // packing so that the structures are layed out properly within the file. +#pragma pack(push) +#pragma pack(2) + + // ICONDIRENTRY contains meta data for an individual icon image within a + // .ico file. + struct ICONDIRENTRY { + BYTE bWidth; + BYTE bHeight; + BYTE bColorCount; + BYTE bReserved; + WORD wPlanes; + WORD wBitCount; + DWORD dwBytesInRes; + DWORD dwImageOffset; + }; + + // ICONDIR Contains information about all the icon images contained within a + // single .ico file. + struct ICONDIR { + WORD idReserved; + WORD idType; + WORD idCount; + ICONDIRENTRY idEntries[1]; + }; + + // Contains the actual icon image. + struct ICONIMAGE { + BITMAPINFOHEADER icHeader; + RGBQUAD icColors[1]; + BYTE icXOR[1]; + BYTE icAND[1]; + }; +#pragma pack(pop) + + // Used for indicating that the .ico contains an icon (rather than a cursor) + // image. This value is set in the |idType| field of the ICONDIR structure. + static const int kResourceTypeIcon = 1; + + // The dimensions of the icon images we insert into the .ico file. + static const int icon_dimensions_[]; + + // Returns true if any pixel in the given pixels buffer has an non-zero alpha. + static bool PixelsHaveAlpha(const uint32* pixels, size_t num_pixels); + + // A helper function that initializes a BITMAPV5HEADER structure with a set + // of values. + static void InitializeBitmapHeader(BITMAPV5HEADER* header, int width, + int height); + + // Given a single SkBitmap object and pointers to the corresponding icon + // structures within the icon data buffer, this function sets the image + // information (dimensions, color depth, etc.) in the icon structures and + // also copies the underlying icon image into the appropriate location. + // + // The function will set the data pointed to by |image_byte_count| with the + // number of image bytes written to the buffer. Note that the number of bytes + // includes only the image data written into the memory pointed to by + // |icon_image|. + static void SetSingleIconImageInformation(const SkBitmap& bitmap, + size_t index, + ICONDIR* icon_dir, + ICONIMAGE* icon_image, + size_t image_offset, + size_t* image_byte_count); + + // Copies the bits of an SkBitmap object into a buffer holding the bits of + // the corresponding image for an icon within the .ico file. + static void CopySkBitmapBitsIntoIconBuffer(const SkBitmap& bitmap, + unsigned char* buffer, + size_t buffer_size); + + // Given a single bitmap, this function creates a set of bitmaps with + // specific dimensions by resizing the given bitmap to the appropriate sizes. + static void CreateResizedBitmapSet(const SkBitmap& bitmap_to_resize, + std::vector<SkBitmap>* bitmaps); + + // Given a set of bitmaps with varying dimensions, this function computes + // the amount of memory needed in order to store the bitmaps as image icons + // in a .ico file. + static size_t ComputeIconFileBufferSize(const std::vector<SkBitmap>& set); + + // A helper function for computing various size components of a given bitmap. + // The different sizes can be used within the various .ico file structures. + // + // |xor_mask_size| - the size, in bytes, of the XOR mask in the ICONIMAGE + // structure. + // |and_mask_size| - the size, in bytes, of the AND mask in the ICONIMAGE + // structure. + // |bytes_in_resource| - the total number of bytes set in the ICONIMAGE + // structure. This value is equal to the sum of the + // bytes in the AND mask and the XOR mask plus the size + // of the BITMAPINFOHEADER structure. Note that since + // only 32bpp are handled by the IconUtil class, the + // icColors field in the ICONIMAGE structure is ignored + // and is not accounted for when computing the + // different size components. + static void ComputeBitmapSizeComponents(const SkBitmap& bitmap, + size_t* xor_mask_size, + size_t* bytes_in_resource); + + // Prevent clients from instantiating objects of that class by declaring the + // ctor/dtor as private. + DISALLOW_IMPLICIT_CONSTRUCTORS(IconUtil); +}; + +#endif // UI_GFX_ICON_UTIL_H_ diff --git a/gfx/icon_util_unittest.cc b/ui/gfx/icon_util_unittest.cc index 43eca49..43eca49 100644 --- a/gfx/icon_util_unittest.cc +++ b/ui/gfx/icon_util_unittest.cc diff --git a/gfx/insets.cc b/ui/gfx/insets.cc index 06cc6aa..06cc6aa 100644 --- a/gfx/insets.cc +++ b/ui/gfx/insets.cc diff --git a/ui/gfx/insets.h b/ui/gfx/insets.h new file mode 100644 index 0000000..31909b4 --- /dev/null +++ b/ui/gfx/insets.h @@ -0,0 +1,94 @@ +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_GFX_INSETS_H_ +#define UI_GFX_INSETS_H_ +#pragma once + +#include "build/build_config.h" + +#if defined(OS_POSIX) && !defined(OS_MACOSX) +#include <gtk/gtkstyle.h> +#endif + +#include <string> + +namespace gfx { + +// +// An insets represents the borders of a container (the space the container must +// leave at each of its edges). +// + +class Insets { + public: + Insets() : top_(0), left_(0), bottom_(0), right_(0) {} + Insets(int top, int left, int bottom, int right) + : top_(top), + left_(left), + bottom_(bottom), + right_(right) {} +#if defined(OS_POSIX) && !defined(OS_MACOSX) + explicit Insets(const GtkBorder& border) + : top_(border.top), + left_(border.left), + bottom_(border.bottom), + right_(border.right) {} +#endif + + ~Insets() {} + + int top() const { return top_; } + int left() const { return left_; } + int bottom() const { return bottom_; } + int right() const { return right_; } + + // Returns the total width taken up by the insets, which is the sum of the + // left and right insets. + int width() const { return left_ + right_; } + + // Returns the total height taken up by the insets, which is the sum of the + // top and bottom insets. + int height() const { return top_ + bottom_; } + + // Returns true if the insets are empty. + bool empty() const { return width() == 0 && height() == 0; } + + void Set(int top, int left, int bottom, int right) { + top_ = top; + left_ = left; + bottom_ = bottom; + right_ = right; + } + + bool operator==(const Insets& insets) const { + return top_ == insets.top_ && left_ == insets.left_ && + bottom_ == insets.bottom_ && right_ == insets.right_; + } + + bool operator!=(const Insets& insets) const { + return !(*this == insets); + } + + Insets& operator+=(const Insets& insets) { + top_ += insets.top_; + left_ += insets.left_; + bottom_ += insets.bottom_; + right_ += insets.right_; + return *this; + } + + // Returns a string representation of the insets. + std::string ToString() const; + + private: + int top_; + int left_; + int bottom_; + int right_; +}; + +} // namespace gfx + +#endif // UI_GFX_INSETS_H_ diff --git a/gfx/insets_unittest.cc b/ui/gfx/insets_unittest.cc index 30d6d7f..30d6d7f 100644 --- a/gfx/insets_unittest.cc +++ b/ui/gfx/insets_unittest.cc diff --git a/gfx/native_theme_linux.cc b/ui/gfx/native_theme_linux.cc index b2087fe..b2087fe 100644 --- a/gfx/native_theme_linux.cc +++ b/ui/gfx/native_theme_linux.cc diff --git a/ui/gfx/native_theme_linux.h b/ui/gfx/native_theme_linux.h new file mode 100644 index 0000000..b557dfc --- /dev/null +++ b/ui/gfx/native_theme_linux.h @@ -0,0 +1,238 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_GFX_NATIVE_THEME_LINUX_H_ +#define UI_GFX_NATIVE_THEME_LINUX_H_ + +#include "base/basictypes.h" +#include "skia/ext/platform_canvas.h" + +namespace skia { +class PlatformCanvas; +} + +namespace gfx { +class Rect; +class Size; + +// Linux theming API. +class NativeThemeLinux { + public: + // The part to be painted / sized. + enum Part { + kScrollbarDownArrow, + kScrollbarLeftArrow, + kScrollbarRightArrow, + kScrollbarUpArrow, + kScrollbarHorizontalThumb, + kScrollbarVerticalThumb, + kScrollbarHorizontalTrack, + kScrollbarVerticalTrack, + kCheckbox, + kRadio, + kPushButton, + kTextField, + kMenuList, + kSliderTrack, + kSliderThumb, + kInnerSpinButton, + kProgressBar, + }; + + // The state of the part. + enum State { + kDisabled, + kHovered, + kNormal, + kPressed, + }; + + // Extra data needed to draw scrollbar track correctly. + struct ScrollbarTrackExtraParams { + int track_x; + int track_y; + int track_width; + int track_height; + }; + + struct ButtonExtraParams { + bool checked; + bool indeterminate; // Whether the button state is indeterminate. + bool is_default; // Whether the button is default button. + SkColor background_color; + }; + + struct TextFieldExtraParams { + bool is_text_area; + bool is_listbox; + SkColor background_color; + }; + + struct MenuListExtraParams { + int arrow_x; + int arrow_y; + SkColor background_color; + }; + + struct SliderExtraParams { + bool vertical; + bool in_drag; + }; + + struct InnerSpinButtonExtraParams { + bool spin_up; + bool read_only; + }; + + struct ProgressBarExtraParams { + bool determinate; + int value_rect_x; + int value_rect_y; + int value_rect_width; + int value_rect_height; + }; + + union ExtraParams { + ScrollbarTrackExtraParams scrollbar_track; + ButtonExtraParams button; + MenuListExtraParams menu_list; + SliderExtraParams slider; + TextFieldExtraParams text_field; + InnerSpinButtonExtraParams inner_spin; + ProgressBarExtraParams progress_bar; + }; + + // Gets our singleton instance. + static NativeThemeLinux* instance(); + + // Return the size of the part. + virtual gfx::Size GetPartSize(Part part) const; + // Paint the part to the canvas. + virtual void Paint(skia::PlatformCanvas* canvas, + Part part, + State state, + const gfx::Rect& rect, + const ExtraParams& extra); + // Supports theme specific colors. + void SetScrollbarColors(unsigned inactive_color, + unsigned active_color, + unsigned track_color) const; + + protected: + NativeThemeLinux(); + virtual ~NativeThemeLinux(); + + // Draw the arrow. Used by scrollbar and inner spin button. + virtual void PaintArrowButton( + skia::PlatformCanvas* gc, + const gfx::Rect& rect, + Part direction, + State state); + // Paint the scrollbar track. Done before the thumb so that it can contain + // alpha. + virtual void PaintScrollbarTrack(skia::PlatformCanvas* canvas, + Part part, + State state, + const ScrollbarTrackExtraParams& extra_params, + const gfx::Rect& rect); + // Draw the scrollbar thumb over the track. + virtual void PaintScrollbarThumb(skia::PlatformCanvas* canvas, + Part part, + State state, + const gfx::Rect& rect); + // Draw the checkbox. + virtual void PaintCheckbox(skia::PlatformCanvas* canvas, + State state, + const gfx::Rect& rect, + const ButtonExtraParams& button); + // Draw the radio. + virtual void PaintRadio(skia::PlatformCanvas* canvas, + State state, + const gfx::Rect& rect, + const ButtonExtraParams& button); + // Draw the push button. + virtual void PaintButton(skia::PlatformCanvas* canvas, + State state, + const gfx::Rect& rect, + const ButtonExtraParams& button); + // Draw the text field. + virtual void PaintTextField(skia::PlatformCanvas* canvas, + State state, + const gfx::Rect& rect, + const TextFieldExtraParams& text); + // Draw the menu list. + virtual void PaintMenuList(skia::PlatformCanvas* canvas, + State state, + const gfx::Rect& rect, + const MenuListExtraParams& menu_list); + // Draw the slider track. + virtual void PaintSliderTrack(skia::PlatformCanvas* canvas, + State state, + const gfx::Rect& rect, + const SliderExtraParams& slider); + // Draw the slider thumb. + virtual void PaintSliderThumb(skia::PlatformCanvas* canvas, + State state, + const gfx::Rect& rect, + const SliderExtraParams& slider); + // Draw the inner spin button. + virtual void PaintInnerSpinButton(skia::PlatformCanvas* canvas, + State state, + const gfx::Rect& rect, + const InnerSpinButtonExtraParams& spin_button); + // Draw the progress bar. + virtual void PaintProgressBar(skia::PlatformCanvas* canvas, + State state, + const gfx::Rect& rect, + const ProgressBarExtraParams& progress_bar); + + protected: + bool IntersectsClipRectInt(skia::PlatformCanvas* canvas, + int x, int y, int w, int h); + + void DrawBitmapInt(skia::PlatformCanvas* canvas, const SkBitmap& bitmap, + int src_x, int src_y, int src_w, int src_h, + int dest_x, int dest_y, int dest_w, int dest_h); + + void DrawTiledImage(SkCanvas* canvas, + const SkBitmap& bitmap, + int src_x, int src_y, + double tile_scale_x, double tile_scale_y, + int dest_x, int dest_y, int w, int h) const; + + SkColor SaturateAndBrighten(SkScalar* hsv, + SkScalar saturate_amount, + SkScalar brighten_amount) const; + + private: + void DrawVertLine(SkCanvas* canvas, + int x, + int y1, + int y2, + const SkPaint& paint) const; + void DrawHorizLine(SkCanvas* canvas, + int x1, + int x2, + int y, + const SkPaint& paint) const; + void DrawBox(SkCanvas* canvas, + const gfx::Rect& rect, + const SkPaint& paint) const; + SkScalar Clamp(SkScalar value, + SkScalar min, + SkScalar max) const; + SkColor OutlineColor(SkScalar* hsv1, SkScalar* hsv2) const; + + static unsigned int scrollbar_width_; + static unsigned int button_length_; + static unsigned int thumb_inactive_color_; + static unsigned int thumb_active_color_; + static unsigned int track_color_; + + DISALLOW_COPY_AND_ASSIGN(NativeThemeLinux); +}; + +} // namespace gfx + +#endif // UI_GFX_NATIVE_THEME_LINUX_H_ diff --git a/gfx/native_theme_win.cc b/ui/gfx/native_theme_win.cc index b563b4f..b563b4f 100644 --- a/gfx/native_theme_win.cc +++ b/ui/gfx/native_theme_win.cc diff --git a/ui/gfx/native_theme_win.h b/ui/gfx/native_theme_win.h new file mode 100644 index 0000000..ff94e52 --- /dev/null +++ b/ui/gfx/native_theme_win.h @@ -0,0 +1,321 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. +// +// A wrapper class for working with custom XP/Vista themes provided in +// uxtheme.dll. This is a singleton class that can be grabbed using +// NativeTheme::instance(). +// For more information on visual style parts and states, see: +// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/userex/topics/partsandstates.asp + +#ifndef UI_GFX_NATIVE_THEME_WIN_H_ +#define UI_GFX_NATIVE_THEME_WIN_H_ +#pragma once + +#include <windows.h> +#include <uxtheme.h> +#include "base/basictypes.h" +#include "gfx/size.h" +#include "third_party/skia/include/core/SkColor.h" + +namespace skia { +class PlatformCanvas; +} // namespace skia + +namespace gfx { + +// TODO: Define class member enums to replace part_id and state_id parameters +// that are currently defined in <vssym32.h>. Afterward, classic_state should +// be removed and class users wouldn't need to include <vssym32.h> anymore. +// This would enable HOT state on non-themed UI (like when RDP'ing) and would +// simplify usage. +// TODO: This class should probably be changed to be platform independent at +// the same time. +class NativeTheme { + public: + enum ThemeName { + BUTTON, + LIST, + MENU, + MENULIST, + SCROLLBAR, + STATUS, + TAB, + TEXTFIELD, + TRACKBAR, + WINDOW, + PROGRESS, + SPIN, + LAST + }; + + // This enumeration is used within PaintMenuArrow in order to indicate the + // direction the menu arrow should point to. + enum MenuArrowDirection { + LEFT_POINTING_ARROW, + RIGHT_POINTING_ARROW + }; + + enum ControlState { + CONTROL_NORMAL, + CONTROL_HIGHLIGHTED, + CONTROL_DISABLED + }; + + typedef HRESULT (WINAPI* DrawThemeBackgroundPtr)(HANDLE theme, + HDC hdc, + int part_id, + int state_id, + const RECT* rect, + const RECT* clip_rect); + typedef HRESULT (WINAPI* DrawThemeBackgroundExPtr)(HANDLE theme, + HDC hdc, + int part_id, + int state_id, + const RECT* rect, + const DTBGOPTS* opts); + typedef HRESULT (WINAPI* GetThemeColorPtr)(HANDLE hTheme, + int part_id, + int state_id, + int prop_id, + COLORREF* color); + typedef HRESULT (WINAPI* GetThemeContentRectPtr)(HANDLE hTheme, + HDC hdc, + int part_id, + int state_id, + const RECT* rect, + RECT* content_rect); + typedef HRESULT (WINAPI* GetThemePartSizePtr)(HANDLE hTheme, + HDC hdc, + int part_id, + int state_id, + RECT* rect, + int ts, + SIZE* size); + typedef HANDLE (WINAPI* OpenThemeDataPtr)(HWND window, + LPCWSTR class_list); + typedef HRESULT (WINAPI* CloseThemeDataPtr)(HANDLE theme); + + typedef void (WINAPI* SetThemeAppPropertiesPtr) (DWORD flags); + typedef BOOL (WINAPI* IsThemeActivePtr)(); + typedef HRESULT (WINAPI* GetThemeIntPtr)(HANDLE hTheme, + int part_id, + int state_id, + int prop_id, + int *value); + + HRESULT PaintButton(HDC hdc, + int part_id, + int state_id, + int classic_state, + RECT* rect) const; + + HRESULT PaintDialogBackground(HDC dc, bool active, RECT* rect) const; + + HRESULT PaintListBackground(HDC dc, bool enabled, RECT* rect) const; + + // |arrow_direction| determines whether the arrow is pointing to the left or + // to the right. In RTL locales, sub-menus open from right to left and + // therefore the menu arrow should point to the left and not to the right. + HRESULT PaintMenuArrow(ThemeName theme, + HDC hdc, + int part_id, + int state_id, + RECT* rect, + MenuArrowDirection arrow_direction, + ControlState state) const; + + HRESULT PaintMenuBackground(ThemeName theme, + HDC hdc, + int part_id, + int state_id, + RECT* rect) const; + + HRESULT PaintMenuCheck(ThemeName theme, + HDC hdc, + int part_id, + int state_id, + RECT* rect, + ControlState state) const; + + HRESULT PaintMenuCheckBackground(ThemeName theme, + HDC hdc, + int part_id, + int state_id, + RECT* rect) const; + + HRESULT PaintMenuGutter(HDC hdc, + int part_id, + int state_id, + RECT* rect) const; + + HRESULT PaintMenuItemBackground(ThemeName theme, + HDC hdc, + int part_id, + int state_id, + bool selected, + RECT* rect) const; + + HRESULT PaintMenuList(HDC hdc, + int part_id, + int state_id, + int classic_state, + RECT* rect) const; + + HRESULT PaintMenuSeparator(HDC hdc, + int part_id, + int state_id, + RECT* rect) const; + + // Paints a scrollbar arrow. |classic_state| should have the appropriate + // classic part number ORed in already. + HRESULT PaintScrollbarArrow(HDC hdc, + int state_id, + int classic_state, + RECT* rect) const; + + // Paints a scrollbar track section. |align_rect| is only used in classic + // mode, and makes sure the checkerboard pattern in |target_rect| is aligned + // with one presumed to be in |align_rect|. + HRESULT PaintScrollbarTrack(HDC hdc, + int part_id, + int state_id, + int classic_state, + RECT* target_rect, + RECT* align_rect, + skia::PlatformCanvas* canvas) const; + + // Paints a scrollbar thumb or gripper. + HRESULT PaintScrollbarThumb(HDC hdc, + int part_id, + int state_id, + int classic_state, + RECT* rect) const; + + HRESULT PaintSpinButton(HDC hdc, + int part_id, + int state_id, + int classic_state, + RECT* rect) const; + + HRESULT PaintStatusGripper(HDC hdc, + int part_id, + int state_id, + int classic_state, + RECT* rect) const; + + HRESULT PaintTabPanelBackground(HDC dc, RECT* rect) const; + + HRESULT PaintTextField(HDC hdc, + int part_id, + int state_id, + int classic_state, + RECT* rect, + COLORREF color, + bool fill_content_area, + bool draw_edges) const; + + HRESULT PaintTrackbar(HDC hdc, + int part_id, + int state_id, + int classic_state, + RECT* rect, + skia::PlatformCanvas* canvas) const; + + HRESULT PaintProgressBar(HDC hdc, + RECT* bar_rect, + RECT* value_rect, + bool determinate, + double animated_seconds, + skia::PlatformCanvas* canvas) const; + + bool IsThemingActive() const; + + HRESULT GetThemePartSize(ThemeName themeName, + HDC hdc, + int part_id, + int state_id, + RECT* rect, + int ts, + SIZE* size) const; + + HRESULT GetThemeColor(ThemeName theme, + int part_id, + int state_id, + int prop_id, + SkColor* color) const; + + // Get the theme color if theming is enabled. If theming is unsupported + // for this part, use Win32's GetSysColor to find the color specified + // by default_sys_color. + SkColor GetThemeColorWithDefault(ThemeName theme, + int part_id, + int state_id, + int prop_id, + int default_sys_color) const; + + HRESULT GetThemeInt(ThemeName theme, + int part_id, + int state_id, + int prop_id, + int *result) const; + + // Get the thickness of the border associated with the specified theme, + // defaulting to GetSystemMetrics edge size if themes are disabled. + // In Classic Windows, borders are typically 2px; on XP+, they are 1px. + Size GetThemeBorderSize(ThemeName theme) const; + + // Disables all theming for top-level windows in the entire process, from + // when this method is called until the process exits. All the other + // methods in this class will continue to work, but their output will ignore + // the user's theme. This is meant for use when running tests that require + // consistent visual results. + void DisableTheming() const; + + // Closes cached theme handles so we can unload the DLL or update our UI + // for a theme change. + void CloseHandles() const; + + // Returns true if classic theme is in use. + bool IsClassicTheme(ThemeName name) const; + + // Gets our singleton instance. + static const NativeTheme* instance(); + + private: + NativeTheme(); + ~NativeTheme(); + + HRESULT PaintFrameControl(HDC hdc, + RECT* rect, + UINT type, + UINT state, + ControlState control_state) const; + + // Returns a handle to the theme data. + HANDLE GetThemeHandle(ThemeName theme_name) const; + + // Function pointers into uxtheme.dll. + DrawThemeBackgroundPtr draw_theme_; + DrawThemeBackgroundExPtr draw_theme_ex_; + GetThemeColorPtr get_theme_color_; + GetThemeContentRectPtr get_theme_content_rect_; + GetThemePartSizePtr get_theme_part_size_; + OpenThemeDataPtr open_theme_; + CloseThemeDataPtr close_theme_; + SetThemeAppPropertiesPtr set_theme_properties_; + IsThemeActivePtr is_theme_active_; + GetThemeIntPtr get_theme_int_; + + // Handle to uxtheme.dll. + HMODULE theme_dll_; + + // A cache of open theme handles. + mutable HANDLE theme_handles_[LAST]; + + DISALLOW_COPY_AND_ASSIGN(NativeTheme); +}; + +} // namespace gfx + +#endif // UI_GFX_NATIVE_THEME_WIN_H_ diff --git a/gfx/native_theme_win_unittest.cc b/ui/gfx/native_theme_win_unittest.cc index b087da6..b087da6 100644 --- a/gfx/native_theme_win_unittest.cc +++ b/ui/gfx/native_theme_win_unittest.cc diff --git a/ui/gfx/native_widget_types.h b/ui/gfx/native_widget_types.h new file mode 100644 index 0000000..bc60777 --- /dev/null +++ b/ui/gfx/native_widget_types.h @@ -0,0 +1,176 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_GFX_NATIVE_WIDGET_TYPES_H_ +#define UI_GFX_NATIVE_WIDGET_TYPES_H_ +#pragma once + +#include "base/basictypes.h" +#include "build/build_config.h" + +// This file provides cross platform typedefs for native widget types. +// NativeWindow: this is a handle to a native, top-level window +// NativeView: this is a handle to a native UI element. It may be the +// same type as a NativeWindow on some platforms. +// NativeViewId: Often, in our cross process model, we need to pass around a +// reference to a "window". This reference will, say, be echoed back from a +// renderer to the browser when it wishes to query its size. On Windows we +// use an HWND for this. +// +// As a rule of thumb - if you're in the renderer, you should be dealing +// with NativeViewIds. This should remind you that you shouldn't be doing +// direct operations on platform widgets from the renderer process. +// +// If you're in the browser, you're probably dealing with NativeViews, +// unless you're in the IPC layer, which will be translating between +// NativeViewIds from the renderer and NativeViews. +// +// NativeEditView: a handle to a native edit-box. The Mac folks wanted this +// specific typedef. +// +// NativeImage: The platform-specific image type used for drawing UI elements +// in the browser. +// +// The name 'View' here meshes with OS X where the UI elements are called +// 'views' and with our Chrome UI code where the elements are also called +// 'views'. + +#if defined(OS_WIN) +#include <windows.h> // NOLINT +typedef struct HFONT__* HFONT; +#elif defined(OS_MACOSX) +struct CGContext; +#ifdef __OBJC__ +@class NSFont; +@class NSImage; +@class NSView; +@class NSWindow; +@class NSTextField; +#else +class NSFont; +class NSImage; +class NSView; +class NSWindow; +class NSTextField; +#endif // __OBJC__ +#elif defined(TOOLKIT_USES_GTK) +typedef struct _PangoFontDescription PangoFontDescription; +typedef struct _GdkCursor GdkCursor; +typedef struct _GdkPixbuf GdkPixbuf; +typedef struct _GdkRegion GdkRegion; +typedef struct _GtkWidget GtkWidget; +typedef struct _GtkWindow GtkWindow; +typedef struct _cairo cairo_t; +#endif +class SkBitmap; + +namespace gfx { + +#if defined(OS_WIN) +typedef HFONT NativeFont; +typedef HWND NativeView; +typedef HWND NativeWindow; +typedef HWND NativeEditView; +typedef HDC NativeDrawingContext; +typedef HCURSOR NativeCursor; +typedef HMENU NativeMenu; +typedef HRGN NativeRegion; +#elif defined(OS_MACOSX) +typedef NSFont* NativeFont; +typedef NSView* NativeView; +typedef NSWindow* NativeWindow; +typedef NSTextField* NativeEditView; +typedef CGContext* NativeDrawingContext; +typedef void* NativeCursor; +typedef void* NativeMenu; +#elif defined(USE_X11) +typedef PangoFontDescription* NativeFont; +typedef GtkWidget* NativeView; +typedef GtkWindow* NativeWindow; +typedef GtkWidget* NativeEditView; +typedef cairo_t* NativeDrawingContext; +typedef GdkCursor* NativeCursor; +typedef GtkWidget* NativeMenu; +typedef GdkRegion* NativeRegion; +#endif + +#if defined(OS_MACOSX) +typedef NSImage NativeImageType; +#elif defined(OS_LINUX) && !defined(TOOLKIT_VIEWS) +typedef GdkPixbuf NativeImageType; +#else +typedef SkBitmap NativeImageType; +#endif +typedef NativeImageType* NativeImage; + +// Note: for test_shell we're packing a pointer into the NativeViewId. So, if +// you make it a type which is smaller than a pointer, you have to fix +// test_shell. +// +// See comment at the top of the file for usage. +typedef intptr_t NativeViewId; + +#if defined(OS_WIN) +// Convert a NativeViewId to a NativeView. +// +// On Windows, we pass an HWND into the renderer. As stated above, the renderer +// should not be performing operations on the view. +static inline NativeView NativeViewFromId(NativeViewId id) { + return reinterpret_cast<NativeView>(id); +} +#define NativeViewFromIdInBrowser(x) NativeViewFromId(x) +#elif defined(OS_POSIX) +// On Mac and Linux, a NativeView is a pointer to an object, and is useless +// outside the process in which it was created. NativeViewFromId should only be +// used inside the appropriate platform ifdef outside of the browser. +// (NativeViewFromIdInBrowser can be used everywhere in the browser.) If your +// cross-platform design involves a call to NativeViewFromId from outside the +// browser it will never work on Mac or Linux and is fundamentally broken. + +// Please do not call this from outside the browser. It won't work; the name +// should give you a subtle hint. +static inline NativeView NativeViewFromIdInBrowser(NativeViewId id) { + return reinterpret_cast<NativeView>(id); +} +#endif // defined(OS_POSIX) + +// Convert a NativeView to a NativeViewId. See the comments at the top of +// this file. +#if defined(OS_WIN) || defined(OS_MACOSX) +static inline NativeViewId IdFromNativeView(NativeView view) { + return reinterpret_cast<NativeViewId>(view); +} +#elif defined(USE_X11) +// Not inlined because it involves pulling too many headers. +NativeViewId IdFromNativeView(NativeView view); +#endif // defined(USE_X11) + + +// PluginWindowHandle is an abstraction wrapping "the types of windows +// used by NPAPI plugins". On Windows it's an HWND, on X it's an X +// window id. +#if defined(OS_WIN) + typedef HWND PluginWindowHandle; + const PluginWindowHandle kNullPluginWindow = NULL; +#elif defined(USE_X11) + typedef unsigned long PluginWindowHandle; + const PluginWindowHandle kNullPluginWindow = 0; +#else + // On OS X we don't have windowed plugins. + // We use a NULL/0 PluginWindowHandle in shared code to indicate there + // is no window present, so mirror that behavior here. + // + // The GPU plugin is currently an exception to this rule. As of this + // writing it uses some NPAPI infrastructure, and minimally we need + // to identify the plugin instance via this window handle. When the + // GPU plugin becomes a full-on GPU process, this typedef can be + // returned to a bool. For now we use a type large enough to hold a + // pointer on 64-bit architectures in case we need this capability. + typedef uint64 PluginWindowHandle; + const PluginWindowHandle kNullPluginWindow = 0; +#endif + +} // namespace gfx + +#endif // UI_GFX_NATIVE_WIDGET_TYPES_H_ diff --git a/gfx/native_widget_types_gtk.cc b/ui/gfx/native_widget_types_gtk.cc index ccf428c..ccf428c 100644 --- a/gfx/native_widget_types_gtk.cc +++ b/ui/gfx/native_widget_types_gtk.cc diff --git a/gfx/path.cc b/ui/gfx/path.cc index e456679..e456679 100644 --- a/gfx/path.cc +++ b/ui/gfx/path.cc diff --git a/ui/gfx/path.h b/ui/gfx/path.h new file mode 100644 index 0000000..9202e8e --- /dev/null +++ b/ui/gfx/path.h @@ -0,0 +1,57 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_GFX_PATH_H_ +#define UI_GFX_PATH_H_ +#pragma once + +#include "base/basictypes.h" +#include "gfx/native_widget_types.h" + +#include "third_party/skia/include/core/SkPath.h" + +namespace gfx { + +class Path : public SkPath { + public: + // Used by Path(Point,size_t) constructor. + struct Point { + int x; + int y; + }; + + Path(); + + // Creates a path populated with the specified points. + Path(const Point* points, size_t count); + + ~Path(); + +#if defined(OS_WIN) || defined(USE_X11) + // Creates a NativeRegion from the path. The caller is responsible for freeing + // resources used by this region. This only supports polygon paths. + NativeRegion CreateNativeRegion() const; + + // Returns the intersection of the two regions. The caller owns the returned + // object. + static gfx::NativeRegion IntersectRegions(gfx::NativeRegion r1, + gfx::NativeRegion r2); + + // Returns the union of the two regions. The caller owns the returned object. + static gfx::NativeRegion CombineRegions(gfx::NativeRegion r1, + gfx::NativeRegion r2); + + // Returns the difference of the two regions. The caller owns the returned + // object. + static gfx::NativeRegion SubtractRegion(gfx::NativeRegion r1, + gfx::NativeRegion r2); +#endif + + private: + DISALLOW_COPY_AND_ASSIGN(Path); +}; + +} + +#endif // UI_GFX_PATH_H_ diff --git a/gfx/path_gtk.cc b/ui/gfx/path_gtk.cc index 2149aad..2149aad 100644 --- a/gfx/path_gtk.cc +++ b/ui/gfx/path_gtk.cc diff --git a/gfx/path_win.cc b/ui/gfx/path_win.cc index b5f206c..b5f206c 100644 --- a/gfx/path_win.cc +++ b/ui/gfx/path_win.cc diff --git a/ui/gfx/platform_font.h b/ui/gfx/platform_font.h new file mode 100644 index 0000000..32cba2c --- /dev/null +++ b/ui/gfx/platform_font.h @@ -0,0 +1,79 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_GFX_PLATFORM_FONT_ +#define UI_GFX_PLATFORM_FONT_ +#pragma once + +#include <string> + +#include "base/ref_counted.h" +#include "base/string16.h" +#include "gfx/native_widget_types.h" + +namespace gfx { + +class Font; + +class PlatformFont : public base::RefCounted<PlatformFont> { + public: + // Create an appropriate PlatformFont implementation. + static PlatformFont* CreateDefault(); + static PlatformFont* CreateFromFont(const Font& other); + static PlatformFont* CreateFromNativeFont(NativeFont native_font); + static PlatformFont* CreateFromNameAndSize(const string16& font_name, + int font_size); + + // Returns a new Font derived from the existing font. + // size_delta is the size to add to the current font. See the single + // argument version of this method for an example. + // The style parameter specifies the new style for the font, and is a + // bitmask of the values: BOLD, ITALIC and UNDERLINED. + virtual Font DeriveFont(int size_delta, int style) const = 0; + + // Returns the number of vertical pixels needed to display characters from + // the specified font. This may include some leading, i.e. height may be + // greater than just ascent + descent. Specifically, the Windows and Mac + // implementations include leading and the Linux one does not. This may + // need to be revisited in the future. + virtual int GetHeight() const = 0; + + // Returns the baseline, or ascent, of the font. + virtual int GetBaseline() const = 0; + + // Returns the average character width for the font. + virtual int GetAverageCharacterWidth() const = 0; + + // Returns the number of horizontal pixels needed to display the specified + // string. + virtual int GetStringWidth(const string16& text) const = 0; + + // Returns the expected number of horizontal pixels needed to display the + // specified length of characters. Call GetStringWidth() to retrieve the + // actual number. + virtual int GetExpectedTextWidth(int length) const = 0; + + // Returns the style of the font. + virtual int GetStyle() const = 0; + + // Returns the font name. + virtual string16 GetFontName() const = 0; + + // Returns the font size in pixels. + virtual int GetFontSize() const = 0; + + // Returns the native font handle. + virtual NativeFont GetNativeFont() const = 0; + + protected: + virtual ~PlatformFont() {} + + private: + friend class base::RefCounted<PlatformFont>; +}; + +} // namespace gfx + +#endif // UI_GFX_PLATFORM_FONT_ + diff --git a/gfx/platform_font_gtk.cc b/ui/gfx/platform_font_gtk.cc index 82b2e06..82b2e06 100644 --- a/gfx/platform_font_gtk.cc +++ b/ui/gfx/platform_font_gtk.cc diff --git a/ui/gfx/platform_font_gtk.h b/ui/gfx/platform_font_gtk.h new file mode 100644 index 0000000..4b265dd --- /dev/null +++ b/ui/gfx/platform_font_gtk.h @@ -0,0 +1,107 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_GFX_PLATFORM_FONT_GTK_ +#define UI_GFX_PLATFORM_FONT_GTK_ +#pragma once + +#include "base/scoped_ptr.h" +#include "gfx/platform_font.h" +#include "third_party/skia/include/core/SkRefCnt.h" + +class SkTypeface; +class SkPaint; + +namespace gfx { + +class PlatformFontGtk : public PlatformFont { + public: + PlatformFontGtk(); + explicit PlatformFontGtk(const Font& other); + explicit PlatformFontGtk(NativeFont native_font); + PlatformFontGtk(const string16& font_name, + int font_size); + + // Converts |gfx_font| to a new pango font. Free the returned font with + // pango_font_description_free(). + static PangoFontDescription* PangoFontFromGfxFont(const gfx::Font& gfx_font); + + // Position as an offset from the height of the drawn text, used to draw + // an underline. This is a negative number, so the underline would be + // drawn at y + height + underline_position; + double underline_position() const; + // The thickness to draw the underline. + double underline_thickness() const; + + // Overridden from PlatformFont: + virtual Font DeriveFont(int size_delta, int style) const; + virtual int GetHeight() const; + virtual int GetBaseline() const; + virtual int GetAverageCharacterWidth() const; + virtual int GetStringWidth(const string16& text) const; + virtual int GetExpectedTextWidth(int length) const; + virtual int GetStyle() const; + virtual string16 GetFontName() const; + virtual int GetFontSize() const; + virtual NativeFont GetNativeFont() const; + + private: + // Create a new instance of this object with the specified properties. Called + // from DeriveFont. + PlatformFontGtk(SkTypeface* typeface, + const string16& name, + int size, + int style); + virtual ~PlatformFontGtk(); + + // Initialize this object. + void InitWithNameAndSize(const string16& font_name, int font_size); + void InitWithTypefaceNameSizeAndStyle(SkTypeface* typeface, + const string16& name, + int size, + int style); + void InitFromPlatformFont(const PlatformFontGtk* other); + + // Potentially slow call to get pango metrics (average width, underline info). + void InitPangoMetrics(); + + // Setup a Skia context to use the current typeface + void PaintSetup(SkPaint* paint) const; + + // Make |this| a copy of |other|. + void CopyFont(const Font& other); + + // The average width of a character, initialized and cached if needed. + double GetAverageWidth() const; + + // These two both point to the same SkTypeface. We use the SkAutoUnref to + // handle the reference counting, but without @typeface_ we would have to + // cast the SkRefCnt from @typeface_helper_ every time. + scoped_ptr<SkAutoUnref> typeface_helper_; + SkTypeface *typeface_; + + // Additional information about the face + // Skia actually expects a family name and not a font name. + string16 font_family_; + int font_size_pixels_; + int style_; + + // Cached metrics, generated at construction + int height_pixels_; + int ascent_pixels_; + + // The pango metrics are much more expensive so we wait until we need them + // to compute them. + bool pango_metrics_inited_; + double average_width_pixels_; + double underline_position_pixels_; + double underline_thickness_pixels_; + + // The default font, used for the default constructor. + static Font* default_font_; +}; + +} // namespace gfx + +#endif // UI_GFX_PLATFORM_FONT_GTK_ diff --git a/ui/gfx/platform_font_mac.h b/ui/gfx/platform_font_mac.h new file mode 100644 index 0000000..123400c --- /dev/null +++ b/ui/gfx/platform_font_mac.h @@ -0,0 +1,57 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_GFX_PLATFORM_FONT_MAC_ +#define UI_GFX_PLATFORM_FONT_MAC_ +#pragma once + +#include "gfx/platform_font.h" + +namespace gfx { + +class PlatformFontMac : public PlatformFont { + public: + PlatformFontMac(); + explicit PlatformFontMac(const Font& other); + explicit PlatformFontMac(NativeFont native_font); + PlatformFontMac(const string16& font_name, + int font_size); + + // Overridden from PlatformFont: + virtual Font DeriveFont(int size_delta, int style) const; + virtual int GetHeight() const; + virtual int GetBaseline() const; + virtual int GetAverageCharacterWidth() const; + virtual int GetStringWidth(const string16& text) const; + virtual int GetExpectedTextWidth(int length) const; + virtual int GetStyle() const; + virtual string16 GetFontName() const; + virtual int GetFontSize() const; + virtual NativeFont GetNativeFont() const; + + private: + PlatformFontMac(const string16& font_name, int font_size, int style); + virtual ~PlatformFontMac() {} + + // Initialize the object with the specified parameters. + void InitWithNameSizeAndStyle(const string16& font_name, + int font_size, + int style); + + // Calculate and cache the font metrics. + void CalculateMetrics(); + + string16 font_name_; + int font_size_; + int style_; + + // Cached metrics, generated at construction + int height_; + int ascent_; + int average_width_; +}; + +} // namespace gfx + +#endif // UI_GFX_PLATFORM_FONT_MAC_ diff --git a/gfx/platform_font_mac.mm b/ui/gfx/platform_font_mac.mm index 4aa9b88..4aa9b88 100644 --- a/gfx/platform_font_mac.mm +++ b/ui/gfx/platform_font_mac.mm diff --git a/gfx/platform_font_win.cc b/ui/gfx/platform_font_win.cc index 8071640..8071640 100644 --- a/gfx/platform_font_win.cc +++ b/ui/gfx/platform_font_win.cc diff --git a/ui/gfx/platform_font_win.h b/ui/gfx/platform_font_win.h new file mode 100644 index 0000000..4b18cd1 --- /dev/null +++ b/ui/gfx/platform_font_win.h @@ -0,0 +1,131 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_GFX_PLATFORM_FONT_WIN_ +#define UI_GFX_PLATFORM_FONT_WIN_ +#pragma once + +#include "base/ref_counted.h" +#include "gfx/platform_font.h" + +namespace gfx { + +class PlatformFontWin : public PlatformFont { + public: + PlatformFontWin(); + explicit PlatformFontWin(const Font& other); + explicit PlatformFontWin(NativeFont native_font); + PlatformFontWin(const string16& font_name, + int font_size); + + // Dialog units to pixels conversion. + // See http://support.microsoft.com/kb/145994 for details. + int horizontal_dlus_to_pixels(int dlus) const { + return dlus * font_ref_->dlu_base_x() / 4; + } + int vertical_dlus_to_pixels(int dlus) const { + return dlus * font_ref_->height() / 8; + } + + // Callback that returns the minimum height that should be used for + // gfx::Fonts. Optional. If not specified, the minimum font size is 0. + typedef int (*GetMinimumFontSizeCallback)(); + static GetMinimumFontSizeCallback get_minimum_font_size_callback; + + // Callback that adjusts a LOGFONT to meet suitability requirements of the + // embedding application. Optional. If not specified, no adjustments are + // performed other than clamping to a minimum font height if + // |get_minimum_font_size_callback| is specified. + typedef void (*AdjustFontCallback)(LOGFONT* lf); + static AdjustFontCallback adjust_font_callback; + + // Overridden from PlatformFont: + virtual Font DeriveFont(int size_delta, int style) const; + virtual int GetHeight() const; + virtual int GetBaseline() const; + virtual int GetAverageCharacterWidth() const; + virtual int GetStringWidth(const string16& text) const; + virtual int GetExpectedTextWidth(int length) const; + virtual int GetStyle() const; + virtual string16 GetFontName() const; + virtual int GetFontSize() const; + virtual NativeFont GetNativeFont() const; + + private: + virtual ~PlatformFontWin() {} + + // Chrome text drawing bottoms out in the Windows GDI functions that take an + // HFONT (an opaque handle into Windows). To avoid lots of GDI object + // allocation and destruction, Font indirectly refers to the HFONT by way of + // an HFontRef. That is, every Font has an HFontRef, which has an HFONT. + // + // HFontRef is reference counted. Upon deletion, it deletes the HFONT. + // By making HFontRef maintain the reference to the HFONT, multiple + // HFontRefs can share the same HFONT, and Font can provide value semantics. + class HFontRef : public base::RefCounted<HFontRef> { + public: + // This constructor takes control of the HFONT, and will delete it when + // the HFontRef is deleted. + HFontRef(HFONT hfont, + int height, + int baseline, + int ave_char_width, + int style, + int dlu_base_x); + + // Accessors + HFONT hfont() const { return hfont_; } + int height() const { return height_; } + int baseline() const { return baseline_; } + int ave_char_width() const { return ave_char_width_; } + int style() const { return style_; } + int dlu_base_x() const { return dlu_base_x_; } + const string16& font_name() const { return font_name_; } + + private: + friend class base::RefCounted<HFontRef>; + + ~HFontRef(); + + const HFONT hfont_; + const int height_; + const int baseline_; + const int ave_char_width_; + const int style_; + // Constants used in converting dialog units to pixels. + const int dlu_base_x_; + string16 font_name_; + + DISALLOW_COPY_AND_ASSIGN(HFontRef); + }; + + // Initializes this object with a copy of the specified HFONT. + void InitWithCopyOfHFONT(HFONT hfont); + + // Initializes this object with the specified font name and size. + void InitWithFontNameAndSize(const string16& font_name, + int font_size); + + // Returns the base font ref. This should ONLY be invoked on the + // UI thread. + static HFontRef* GetBaseFontRef(); + + // Creates and returns a new HFONTRef from the specified HFONT. + static HFontRef* CreateHFontRef(HFONT font); + + // Creates a new PlatformFontWin with the specified HFontRef. Used when + // constructing a Font from a HFONT we don't want to copy. + explicit PlatformFontWin(HFontRef* hfont_ref); + + // Reference to the base font all fonts are derived from. + static HFontRef* base_font_ref_; + + // Indirect reference to the HFontRef, which references the underlying HFONT. + scoped_refptr<HFontRef> font_ref_; +}; + +} // namespace gfx + +#endif // UI_GFX_PLATFORM_FONT_WIN_ + diff --git a/gfx/point.cc b/ui/gfx/point.cc index d601580..d601580 100644 --- a/gfx/point.cc +++ b/ui/gfx/point.cc diff --git a/ui/gfx/point.h b/ui/gfx/point.h new file mode 100644 index 0000000..b208c07 --- /dev/null +++ b/ui/gfx/point.h @@ -0,0 +1,101 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_GFX_POINT_H_ +#define UI_GFX_POINT_H_ +#pragma once + +#include "build/build_config.h" + +#include <iosfwd> + +#if defined(OS_WIN) +typedef unsigned long DWORD; +typedef struct tagPOINT POINT; +#elif defined(OS_MACOSX) +#include <ApplicationServices/ApplicationServices.h> +#endif + +namespace gfx { + +// A point has an x and y coordinate. +class Point { + public: + Point(); + Point(int x, int y); +#if defined(OS_WIN) + // |point| is a DWORD value that contains a coordinate. The x-coordinate is + // the low-order short and the y-coordinate is the high-order short. This + // value is commonly acquired from GetMessagePos/GetCursorPos. + explicit Point(DWORD point); + explicit Point(const POINT& point); + Point& operator=(const POINT& point); +#elif defined(OS_MACOSX) + explicit Point(const CGPoint& point); +#endif + + ~Point() {} + + int x() const { return x_; } + int y() const { return y_; } + + void SetPoint(int x, int y) { + x_ = x; + y_ = y; + } + + void set_x(int x) { x_ = x; } + void set_y(int y) { y_ = y; } + + void Offset(int delta_x, int delta_y) { + x_ += delta_x; + y_ += delta_y; + } + + Point Add(const Point& other) const{ + Point copy = *this; + copy.Offset(other.x_, other.y_); + return copy; + } + + Point Subtract(const Point& other) const { + Point copy = *this; + copy.Offset(-other.x_, -other.y_); + return copy; + } + + bool operator==(const Point& rhs) const { + return x_ == rhs.x_ && y_ == rhs.y_; + } + + bool operator!=(const Point& rhs) const { + return !(*this == rhs); + } + + // A point is less than another point if its y-value is closer + // to the origin. If the y-values are the same, then point with + // the x-value closer to the origin is considered less than the + // other. + // This comparison is required to use Points in sets, or sorted + // vectors. + bool operator<(const Point& rhs) const { + return (y_ == rhs.y_) ? (x_ < rhs.x_) : (y_ < rhs.y_); + } + +#if defined(OS_WIN) + POINT ToPOINT() const; +#elif defined(OS_MACOSX) + CGPoint ToCGPoint() const; +#endif + + private: + int x_; + int y_; +}; + +std::ostream& operator<<(std::ostream& out, const gfx::Point& p); + +} // namespace gfx + +#endif // UI_GFX_POINT_H_ diff --git a/gfx/rect.cc b/ui/gfx/rect.cc index a1a72cb..a1a72cb 100644 --- a/gfx/rect.cc +++ b/ui/gfx/rect.cc diff --git a/ui/gfx/rect.h b/ui/gfx/rect.h new file mode 100644 index 0000000..1a1d9e6 --- /dev/null +++ b/ui/gfx/rect.h @@ -0,0 +1,184 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Defines a simple integer rectangle class. The containment semantics +// are array-like; that is, the coordinate (x, y) is considered to be +// contained by the rectangle, but the coordinate (x + width, y) is not. +// The class will happily let you create malformed rectangles (that is, +// rectangles with negative width and/or height), but there will be assertions +// in the operations (such as Contains()) to complain in this case. + +#ifndef UI_GFX_RECT_H_ +#define UI_GFX_RECT_H_ +#pragma once + +#include <iosfwd> + +#include "gfx/point.h" +#include "gfx/size.h" + +#if defined(OS_WIN) +typedef struct tagRECT RECT; +#elif defined(USE_X11) +typedef struct _GdkRectangle GdkRectangle; +#endif + +namespace gfx { + +class Insets; + +class Rect { + public: + Rect(); + Rect(int width, int height); + Rect(int x, int y, int width, int height); +#if defined(OS_WIN) + explicit Rect(const RECT& r); +#elif defined(OS_MACOSX) + explicit Rect(const CGRect& r); +#elif defined(USE_X11) + explicit Rect(const GdkRectangle& r); +#endif + explicit Rect(const gfx::Size& size); + Rect(const gfx::Point& origin, const gfx::Size& size); + + ~Rect() {} + +#if defined(OS_WIN) + Rect& operator=(const RECT& r); +#elif defined(OS_MACOSX) + Rect& operator=(const CGRect& r); +#elif defined(USE_X11) + Rect& operator=(const GdkRectangle& r); +#endif + + int x() const { return origin_.x(); } + void set_x(int x) { origin_.set_x(x); } + + int y() const { return origin_.y(); } + void set_y(int y) { origin_.set_y(y); } + + int width() const { return size_.width(); } + void set_width(int width) { size_.set_width(width); } + + int height() const { return size_.height(); } + void set_height(int height) { size_.set_height(height); } + + const gfx::Point& origin() const { return origin_; } + void set_origin(const gfx::Point& origin) { origin_ = origin; } + + const gfx::Size& size() const { return size_; } + void set_size(const gfx::Size& size) { size_ = size; } + + int right() const { return x() + width(); } + int bottom() const { return y() + height(); } + + void SetRect(int x, int y, int width, int height); + + // Shrink the rectangle by a horizontal and vertical distance on all sides. + void Inset(int horizontal, int vertical) { + Inset(horizontal, vertical, horizontal, vertical); + } + + // Shrink the rectangle by the given insets. + void Inset(const gfx::Insets& insets); + + // Shrink the rectangle by the specified amount on each side. + void Inset(int left, int top, int right, int bottom); + + // Move the rectangle by a horizontal and vertical distance. + void Offset(int horizontal, int vertical); + void Offset(const gfx::Point& point) { + Offset(point.x(), point.y()); + } + + // Returns true if the area of the rectangle is zero. + bool IsEmpty() const { return size_.IsEmpty(); } + + bool operator==(const Rect& other) const; + + bool operator!=(const Rect& other) const { + return !(*this == other); + } + + // A rect is less than another rect if its origin is less than + // the other rect's origin. If the origins are equal, then the + // shortest rect is less than the other. If the origin and the + // height are equal, then the narrowest rect is less than. + // This comparison is required to use Rects in sets, or sorted + // vectors. + bool operator<(const Rect& other) const; + +#if defined(OS_WIN) + // Construct an equivalent Win32 RECT object. + RECT ToRECT() const; +#elif defined(USE_X11) + GdkRectangle ToGdkRectangle() const; +#elif defined(OS_MACOSX) + // Construct an equivalent CoreGraphics object. + CGRect ToCGRect() const; +#endif + + // Returns true if the point identified by point_x and point_y falls inside + // this rectangle. The point (x, y) is inside the rectangle, but the + // point (x + width, y + height) is not. + bool Contains(int point_x, int point_y) const; + + // Returns true if the specified point is contained by this rectangle. + bool Contains(const gfx::Point& point) const { + return Contains(point.x(), point.y()); + } + + // Returns true if this rectangle contains the specified rectangle. + bool Contains(const Rect& rect) const; + + // Returns true if this rectangle intersects the specified rectangle. + bool Intersects(const Rect& rect) const; + + // Computes the intersection of this rectangle with the given rectangle. + Rect Intersect(const Rect& rect) const; + + // Computes the union of this rectangle with the given rectangle. The union + // is the smallest rectangle containing both rectangles. + Rect Union(const Rect& rect) const; + + // Computes the rectangle resulting from subtracting |rect| from |this|. If + // |rect| does not intersect completely in either the x- or y-direction, then + // |*this| is returned. If |rect| contains |this|, then an empty Rect is + // returned. + Rect Subtract(const Rect& rect) const; + + // Returns true if this rectangle equals that of the supplied rectangle. + bool Equals(const Rect& rect) const { + return *this == rect; + } + + // Fits as much of the receiving rectangle into the supplied rectangle as + // possible, returning the result. For example, if the receiver had + // a x-location of 2 and a width of 4, and the supplied rectangle had + // an x-location of 0 with a width of 5, the returned rectangle would have + // an x-location of 1 with a width of 4. + Rect AdjustToFit(const Rect& rect) const; + + // Returns the center of this rectangle. + Point CenterPoint() const; + + // Return a rectangle that has the same center point but with a size capped + // at given |size|. + Rect Center(const gfx::Size& size) const; + + // Returns true if this rectangle shares an entire edge (i.e., same width or + // same height) with the given rectangle, and the rectangles do not overlap. + bool SharesEdgeWith(const gfx::Rect& rect) const; + + private: + gfx::Point origin_; + gfx::Size size_; +}; + +std::ostream& operator<<(std::ostream& out, const gfx::Rect& r); + +} // namespace gfx + +#endif // UI_GFX_RECT_H_ diff --git a/gfx/rect_unittest.cc b/ui/gfx/rect_unittest.cc index f5b4d9b..f5b4d9b 100644 --- a/gfx/rect_unittest.cc +++ b/ui/gfx/rect_unittest.cc diff --git a/gfx/run_all_unittests.cc b/ui/gfx/run_all_unittests.cc index 834d7c8..834d7c8 100644 --- a/gfx/run_all_unittests.cc +++ b/ui/gfx/run_all_unittests.cc diff --git a/ui/gfx/scoped_cg_context_state_mac.h b/ui/gfx/scoped_cg_context_state_mac.h new file mode 100644 index 0000000..6380bf1 --- /dev/null +++ b/ui/gfx/scoped_cg_context_state_mac.h @@ -0,0 +1,30 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_GFX_SCOPED_CG_CONTEXT_STATE_MAC_H_ +#define UI_GFX_SCOPED_CG_CONTEXT_STATE_MAC_H_ + +#import <QuartzCore/QuartzCore.h> + +namespace gfx { + +class ScopedCGContextSaveGState { + public: + explicit ScopedCGContextSaveGState(CGContextRef context) : context_(context) { + CGContextSaveGState(context_); + } + + ~ScopedCGContextSaveGState() { + CGContextRestoreGState(context_); + } + + private: + CGContextRef context_; + + DISALLOW_COPY_AND_ASSIGN(ScopedCGContextSaveGState); +}; + +} // namespace gfx + +#endif // UI_GFX_SCOPED_CG_CONTEXT_STATE_MAC_H_ diff --git a/ui/gfx/scoped_image.h b/ui/gfx/scoped_image.h new file mode 100644 index 0000000..58cb900f --- /dev/null +++ b/ui/gfx/scoped_image.h @@ -0,0 +1,147 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_GFX_SCOPED_IMAGE_H_ +#define UI_GFX_SCOPED_IMAGE_H_ +#pragma once + +#include "base/basictypes.h" +#include "build/build_config.h" +#include "gfx/native_widget_types.h" +#include "third_party/skia/include/core/SkBitmap.h" + +#if defined(OS_LINUX) +#include <glib-object.h> +#elif defined(OS_MACOSX) +#include "base/mac/mac_util.h" +#endif + +namespace gfx { + +namespace internal { + +// ScopedImage is class that encapsulates one of the three platform-specific +// images used: SkBitmap, NSImage, and GdkPixbuf. This is the abstract interface +// that all ScopedImages respond to. This wrapper expects to own the image it +// holds, unless it is Release()ed or Free()ed. +// +// This class is abstract and callers should use the specialized versions below, +// which are not in the internal namespace. +template <class ImageType> +class ScopedImage { + public: + virtual ~ScopedImage() {} + + // Frees the actual image that this boxes. + virtual void Free() = 0; + + // Returns the image that this boxes. + ImageType* Get() { + return image_; + } + + // Frees the current image and sets a new one. + void Set(ImageType* new_image) { + Free(); + image_ = new_image; + } + + // Returns the image this boxes and relinquishes ownership. + ImageType* Release() { + ImageType* tmp = image_; + image_ = NULL; + return tmp; + } + + protected: + explicit ScopedImage(ImageType* image) : image_(image) {} + ImageType* image_; + + private: + DISALLOW_COPY_AND_ASSIGN(ScopedImage); +}; + +} // namespace internal + +// Generic template. +template <class ImageType = gfx::NativeImageType> +class ScopedImage : public gfx::internal::ScopedImage<ImageType> { + public: + explicit ScopedImage(gfx::NativeImage image) + : gfx::internal::ScopedImage<ImageType>(image) {} + + private: + DISALLOW_COPY_AND_ASSIGN(ScopedImage<ImageType>); +}; + +// Specialization for SkBitmap on all platforms. +template <> +class ScopedImage<SkBitmap> : public gfx::internal::ScopedImage<SkBitmap> { + public: + explicit ScopedImage(SkBitmap* image) + : gfx::internal::ScopedImage<SkBitmap>(image) {} + virtual ~ScopedImage() { + Free(); + } + + virtual void Free() { + delete image_; + image_ = NULL; + } + + private: + DISALLOW_COPY_AND_ASSIGN(ScopedImage); +}; + +// Specialization for the NSImage type on Mac OS X. +#if defined(OS_MACOSX) +template <> +class ScopedImage<NSImage> : public gfx::internal::ScopedImage<NSImage> { + public: + explicit ScopedImage(NSImage* image) + : gfx::internal::ScopedImage<NSImage>(image) {} + virtual ~ScopedImage() { + Free(); + } + + virtual void Free() { + base::mac::NSObjectRelease(image_); + image_ = NULL; + } + + private: + DISALLOW_COPY_AND_ASSIGN(ScopedImage); +}; +#endif // defined(OS_MACOSX) + +// Specialization for the GdkPixbuf type on Linux. +#if defined(OS_LINUX) +template <> +class ScopedImage<GdkPixbuf> : public gfx::internal::ScopedImage<GdkPixbuf> { + public: + explicit ScopedImage(GdkPixbuf* image) + : gfx::internal::ScopedImage<GdkPixbuf>(image) {} + virtual ~ScopedImage() { + Free(); + } + + virtual void Free() { + if (image_) { + g_object_unref(image_); + image_ = NULL; + } + } + + private: + DISALLOW_COPY_AND_ASSIGN(ScopedImage); +}; +#endif // defined(OS_LINUX) + +// Typedef ScopedNativeImage to the default template argument. This allows for +// easy exchange between gfx::NativeImage and a gfx::ScopedNativeImage. +typedef ScopedImage<> ScopedNativeImage; + +} // namespace gfx + +#endif // UI_GFX_SCOPED_IMAGE_H_ diff --git a/gfx/scoped_image_unittest.cc b/ui/gfx/scoped_image_unittest.cc index 8e8b312..8e8b312 100644 --- a/gfx/scoped_image_unittest.cc +++ b/ui/gfx/scoped_image_unittest.cc diff --git a/gfx/scrollbar_size.cc b/ui/gfx/scrollbar_size.cc index 426b0ac..426b0ac 100644 --- a/gfx/scrollbar_size.cc +++ b/ui/gfx/scrollbar_size.cc diff --git a/ui/gfx/scrollbar_size.h b/ui/gfx/scrollbar_size.h new file mode 100644 index 0000000..771b9db --- /dev/null +++ b/ui/gfx/scrollbar_size.h @@ -0,0 +1,18 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_GFX_SCROLLBAR_SIZE_H_ +#define UI_GFX_SCROLLBAR_SIZE_H_ +#pragma once + +namespace gfx { + +// This should return the thickness, in pixels, of a scrollbar in web content. +// This needs to match the values in WebCore's +// ScrollbarThemeChromiumXXX.cpp::scrollbarThickness(). +int scrollbar_size(); + +} // namespace gfx + +#endif // UI_GFX_SCROLLBAR_SIZE_H_ diff --git a/gfx/size.cc b/ui/gfx/size.cc index 6e5528e..6e5528e 100644 --- a/gfx/size.cc +++ b/ui/gfx/size.cc diff --git a/ui/gfx/size.h b/ui/gfx/size.h new file mode 100644 index 0000000..55468eae --- /dev/null +++ b/ui/gfx/size.h @@ -0,0 +1,82 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_GFX_SIZE_H_ +#define UI_GFX_SIZE_H_ +#pragma once + +#include "build/build_config.h" + +#include <iosfwd> + +#if defined(OS_WIN) +typedef struct tagSIZE SIZE; +#elif defined(OS_MACOSX) +#include <ApplicationServices/ApplicationServices.h> +#endif + +namespace gfx { + +// A size has width and height values. +class Size { + public: + Size() : width_(0), height_(0) {} + Size(int width, int height); +#if defined(OS_MACOSX) + explicit Size(const CGSize& s); +#endif + + ~Size() {} + +#if defined(OS_MACOSX) + Size& operator=(const CGSize& s); +#endif + + int width() const { return width_; } + int height() const { return height_; } + + int GetArea() const { return width_ * height_; } + + void SetSize(int width, int height) { + set_width(width); + set_height(height); + } + + void Enlarge(int width, int height) { + set_width(width_ + width); + set_height(height_ + height); + } + + void set_width(int width); + void set_height(int height); + + bool operator==(const Size& s) const { + return width_ == s.width_ && height_ == s.height_; + } + + bool operator!=(const Size& s) const { + return !(*this == s); + } + + bool IsEmpty() const { + // Size doesn't allow negative dimensions, so testing for 0 is enough. + return (width_ == 0) || (height_ == 0); + } + +#if defined(OS_WIN) + SIZE ToSIZE() const; +#elif defined(OS_MACOSX) + CGSize ToCGSize() const; +#endif + + private: + int width_; + int height_; +}; + +std::ostream& operator<<(std::ostream& out, const gfx::Size& s); + +} // namespace gfx + +#endif // UI_GFX_SIZE_H_ diff --git a/gfx/skbitmap_operations.cc b/ui/gfx/skbitmap_operations.cc index 6899553..6899553 100644 --- a/gfx/skbitmap_operations.cc +++ b/ui/gfx/skbitmap_operations.cc diff --git a/ui/gfx/skbitmap_operations.h b/ui/gfx/skbitmap_operations.h new file mode 100644 index 0000000..12ae86a --- /dev/null +++ b/ui/gfx/skbitmap_operations.h @@ -0,0 +1,102 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_GFX_SKBITMAP_OPERATIONS_H_ +#define UI_GFX_SKBITMAP_OPERATIONS_H_ +#pragma once + +#include "base/gtest_prod_util.h" +#include "gfx/color_utils.h" + +class SkBitmap; + +class SkBitmapOperations { + public: + // Create a bitmap that is an inverted image of the passed in image. + // Each color becomes its inverse in the color wheel. So (255, 15, 0) becomes + // (0, 240, 255). The alpha value is not inverted. + static SkBitmap CreateInvertedBitmap(const SkBitmap& image); + + // Create a bitmap that is a superimposition of the second bitmap on top of + // the first. The provided bitmaps must use have the kARGB_8888_Config config + // and be of equal dimensions. + static SkBitmap CreateSuperimposedBitmap(const SkBitmap& first, + const SkBitmap& second); + + // Create a bitmap that is a blend of two others. The alpha argument + // specifies the opacity of the second bitmap. The provided bitmaps must + // use have the kARGB_8888_Config config and be of equal dimensions. + static SkBitmap CreateBlendedBitmap(const SkBitmap& first, + const SkBitmap& second, + double alpha); + + // Create a bitmap that is the original bitmap masked out by the mask defined + // in the alpha bitmap. The images must use the kARGB_8888_Config config and + // be of equal dimensions. + static SkBitmap CreateMaskedBitmap(const SkBitmap& first, + const SkBitmap& alpha); + + // We create a button background image by compositing the color and image + // together, then applying the mask. This is a highly specialized composite + // operation that is the equivalent of drawing a background in |color|, + // tiling |image| over the top, and then masking the result out with |mask|. + // The images must use kARGB_8888_Config config. + static SkBitmap CreateButtonBackground(SkColor color, + const SkBitmap& image, + const SkBitmap& mask); + + // Shift a bitmap's HSL values. The shift values are in the range of 0-1, + // with the option to specify -1 for 'no change'. The shift values are + // defined as: + // hsl_shift[0] (hue): The absolute hue value for the image - 0 and 1 map + // to 0 and 360 on the hue color wheel (red). + // hsl_shift[1] (saturation): A saturation shift for the image, with the + // following key values: + // 0 = remove all color. + // 0.5 = leave unchanged. + // 1 = fully saturate the image. + // hsl_shift[2] (lightness): A lightness shift for the image, with the + // following key values: + // 0 = remove all lightness (make all pixels black). + // 0.5 = leave unchanged. + // 1 = full lightness (make all pixels white). + static SkBitmap CreateHSLShiftedBitmap(const SkBitmap& bitmap, + color_utils::HSL hsl_shift); + + // Create a bitmap that is cropped from another bitmap. This is special + // because it tiles the original bitmap, so your coordinates can extend + // outside the bounds of the original image. + static SkBitmap CreateTiledBitmap(const SkBitmap& bitmap, + int src_x, int src_y, + int dst_w, int dst_h); + + // Iteratively downsamples by 2 until the bitmap is no smaller than the + // input size. The normal use of this is to downsample the bitmap "close" to + // the final size, and then use traditional resampling on the result. + // Because the bitmap will be closer to the final size, it will be faster, + // and linear interpolation will generally work well as a second step. + static SkBitmap DownsampleByTwoUntilSize(const SkBitmap& bitmap, + int min_w, int min_h); + + // Makes a bitmap half has large in each direction by averaging groups of + // 4 pixels. This is one step in generating a mipmap. + static SkBitmap DownsampleByTwo(const SkBitmap& bitmap); + + // Unpremultiplies all pixels in |bitmap|. You almost never want to call + // this, as |SkBitmap|s are always premultiplied by conversion. Call this + // only if you will pass the bitmap's data into a system function that + // doesn't expect premultiplied colors. + static SkBitmap UnPreMultiply(const SkBitmap& bitmap); + + // Transpose the pixels in |bitmap| by swapping x and y. + static SkBitmap CreateTransposedBtmap(const SkBitmap& bitmap); + + private: + SkBitmapOperations(); // Class for scoping only. + + FRIEND_TEST_ALL_PREFIXES(SkBitmapOperationsTest, DownsampleByTwo); + FRIEND_TEST_ALL_PREFIXES(SkBitmapOperationsTest, DownsampleByTwoSmall); +}; + +#endif // UI_GFX_SKBITMAP_OPERATIONS_H_ diff --git a/gfx/skbitmap_operations_unittest.cc b/ui/gfx/skbitmap_operations_unittest.cc index bcad287..bcad287 100644 --- a/gfx/skbitmap_operations_unittest.cc +++ b/ui/gfx/skbitmap_operations_unittest.cc diff --git a/gfx/skia_util.cc b/ui/gfx/skia_util.cc index 865f8fda..865f8fda 100644 --- a/gfx/skia_util.cc +++ b/ui/gfx/skia_util.cc diff --git a/ui/gfx/skia_util.h b/ui/gfx/skia_util.h new file mode 100644 index 0000000..619ff37 --- /dev/null +++ b/ui/gfx/skia_util.h @@ -0,0 +1,39 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_GFX_SKIA_UTIL_H_ +#define UI_GFX_SKIA_UTIL_H_ +#pragma once + +#include "third_party/skia/include/core/SkColor.h" +#include "third_party/skia/include/core/SkRect.h" + +class SkBitmap; +class SkShader; + +namespace gfx { + +class Rect; + +// Convert between Skia and gfx rect types. +SkRect RectToSkRect(const gfx::Rect& rect); +gfx::Rect SkRectToRect(const SkRect& rect); + +// Creates a vertical gradient shader. The caller owns the shader. +// Example usage to avoid leaks: +// SkSafeUnref(paint.setShader(gfx::CreateGradientShader(0, 10, red, blue))); +// +// (The old shader in the paint, if any, needs to be freed, and SkSafeUnref will +// handle the NULL case.) +SkShader* CreateGradientShader(int start_point, + int end_point, + SkColor start_color, + SkColor end_color); + +// Returns true if the two bitmaps contain the same pixels. +bool BitmapsAreEqual(const SkBitmap& bitmap1, const SkBitmap& bitmap2); + +} // namespace gfx; + +#endif // UI_GFX_SKIA_UTIL_H_ diff --git a/gfx/skia_utils_gtk.cc b/ui/gfx/skia_utils_gtk.cc index 8ed4bec..8ed4bec 100644 --- a/gfx/skia_utils_gtk.cc +++ b/ui/gfx/skia_utils_gtk.cc diff --git a/ui/gfx/skia_utils_gtk.h b/ui/gfx/skia_utils_gtk.h new file mode 100644 index 0000000..5682f09 --- /dev/null +++ b/ui/gfx/skia_utils_gtk.h @@ -0,0 +1,23 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_GFX_SKIA_UTILS_GTK_H_ +#define UI_GFX_SKIA_UTILS_GTK_H_ +#pragma once + +#include "third_party/skia/include/core/SkColor.h" + +typedef struct _GdkColor GdkColor; + +namespace gfx { + +// Converts GdkColors to the ARGB layout Skia expects. +SkColor GdkColorToSkColor(GdkColor color); + +// Converts ARGB to GdkColor. +GdkColor SkColorToGdkColor(SkColor color); + +} // namespace gfx + +#endif // UI_GFX_SKIA_UTILS_GTK_H_ diff --git a/gfx/test_suite.cc b/ui/gfx/test_suite.cc index 02e1f7f..02e1f7f 100644 --- a/gfx/test_suite.cc +++ b/ui/gfx/test_suite.cc diff --git a/ui/gfx/test_suite.h b/ui/gfx/test_suite.h new file mode 100644 index 0000000..488ea31 --- /dev/null +++ b/ui/gfx/test_suite.h @@ -0,0 +1,24 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_GFX_TEST_SUITE_H_ +#define UI_GFX_TEST_SUITE_H_ +#pragma once + +#include <string> + +#include "base/test/test_suite.h" +#include "build/build_config.h" + +class GfxTestSuite : public base::TestSuite { + public: + GfxTestSuite(int argc, char** argv); + + protected: + // Overridden from base::TestSuite: + virtual void Initialize(); + virtual void Shutdown(); +}; + +#endif // UI_GFX_TEST_SUITE_H_ diff --git a/gfx/win_util.cc b/ui/gfx/win_util.cc index 9941a65..9941a65 100644 --- a/gfx/win_util.cc +++ b/ui/gfx/win_util.cc diff --git a/ui/gfx/win_util.h b/ui/gfx/win_util.h new file mode 100644 index 0000000..3414f13 --- /dev/null +++ b/ui/gfx/win_util.h @@ -0,0 +1,20 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_GFX_WIN_UTIL_H_ +#define UI_GFX_WIN_UTIL_H_ +#pragma once + +namespace gfx { + +// Returns true if Direct2d is available, false otherwise. +bool Direct2dIsAvailable(); + +// Returns true if DirectWrite is available, false otherwise. +bool DirectWriteIsAvailable(); + +} // namespace gfx; + +#endif // UI_GFX_WIN_UTIL_H_ + diff --git a/webkit/support/webkit_support.gypi b/webkit/support/webkit_support.gypi index d4b1192..5b682c0 100644 --- a/webkit/support/webkit_support.gypi +++ b/webkit/support/webkit_support.gypi @@ -11,7 +11,7 @@ 'target_name': 'webkit_support', 'type': '<(library)', 'dependencies': [ - '<(DEPTH)/gfx/gfx.gyp:gfx', + '<(DEPTH)/ui/gfx/gfx.gyp:gfx', '<(DEPTH)/media/media.gyp:media', '<(DEPTH)/skia/skia.gyp:skia', '<(DEPTH)/testing/gtest.gyp:gtest', diff --git a/webkit/tools/test_shell/test_shell.gypi b/webkit/tools/test_shell/test_shell.gypi index 1d453c4..935d339 100644 --- a/webkit/tools/test_shell/test_shell.gypi +++ b/webkit/tools/test_shell/test_shell.gypi @@ -168,7 +168,7 @@ 'action_name': 'test_shell_repack', 'variables': { 'pak_inputs': [ - '<(SHARED_INTERMEDIATE_DIR)/gfx/gfx_resources.pak', + '<(SHARED_INTERMEDIATE_DIR)/ui/gfx/gfx_resources.pak', '<(SHARED_INTERMEDIATE_DIR)/net/net_resources.pak', '<(SHARED_INTERMEDIATE_DIR)/test_shell/test_shell_resources.pak', '<(SHARED_INTERMEDIATE_DIR)/webkit/webkit_chromium_resources.pak', @@ -324,7 +324,7 @@ ], }, { # OS != "mac" 'dependencies': [ - '<(DEPTH)/gfx/gfx.gyp:gfx_resources', + '<(DEPTH)/ui/gfx/gfx.gyp:gfx_resources', '<(DEPTH)/net/net.gyp:net_resources', '<(DEPTH)/webkit/support/webkit_support.gyp:webkit_resources', '<(DEPTH)/webkit/support/webkit_support.gyp:webkit_strings', |