| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef APP_GFX_CHROME_CANVAS_H_ | 5 #ifndef APP_GFX_CHROME_CANVAS_H_ |
| 6 #define APP_GFX_CHROME_CANVAS_H_ | 6 #define APP_GFX_CHROME_CANVAS_H_ |
| 7 | 7 |
| 8 #if defined(OS_WIN) | 8 #if defined(OS_WIN) |
| 9 #include <windows.h> | 9 #include <windows.h> |
| 10 #endif | 10 #endif |
| 11 | 11 |
| 12 #include <string> | 12 #include <string> |
| 13 | 13 |
| 14 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
| 15 #include "skia/ext/platform_canvas.h" | 15 #include "skia/ext/platform_canvas.h" |
| 16 | 16 |
| 17 class ChromeFont; | |
| 18 namespace gfx { | 17 namespace gfx { |
| 18 class Font; |
| 19 class Rect; | 19 class Rect; |
| 20 } | 20 } |
| 21 | 21 |
| 22 #if defined(OS_LINUX) | 22 #if defined(OS_LINUX) |
| 23 typedef struct _cairo cairo_t; | 23 typedef struct _cairo cairo_t; |
| 24 #endif | 24 #endif |
| 25 | 25 |
| 26 // ChromeCanvas is the SkCanvas used by Views for all painting. It | 26 // ChromeCanvas is the SkCanvas used by Views for all painting. It |
| 27 // provides a handful of methods for the common operations used throughout | 27 // provides a handful of methods for the common operations used throughout |
| 28 // Views. With few exceptions, you should NOT create a ChromeCanvas directly, | 28 // Views. With few exceptions, you should NOT create a ChromeCanvas directly, |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 void DrawBitmapInt(const SkBitmap& bitmap, int src_x, int src_y, int src_w, | 145 void DrawBitmapInt(const SkBitmap& bitmap, int src_x, int src_y, int src_w, |
| 146 int src_h, int dest_x, int dest_y, int dest_w, int dest_h, | 146 int src_h, int dest_x, int dest_y, int dest_w, int dest_h, |
| 147 bool filter); | 147 bool filter); |
| 148 void DrawBitmapInt(const SkBitmap& bitmap, int src_x, int src_y, int src_w, | 148 void DrawBitmapInt(const SkBitmap& bitmap, int src_x, int src_y, int src_w, |
| 149 int src_h, int dest_x, int dest_y, int dest_w, int dest_h, | 149 int src_h, int dest_x, int dest_y, int dest_w, int dest_h, |
| 150 bool filter, const SkPaint& paint); | 150 bool filter, const SkPaint& paint); |
| 151 | 151 |
| 152 // Draws text with the specified color, font and location. The text is | 152 // Draws text with the specified color, font and location. The text is |
| 153 // aligned to the left, vertically centered, clipped to the region. If the | 153 // aligned to the left, vertically centered, clipped to the region. If the |
| 154 // text is too big, it is truncated and '...' is added to the end. | 154 // text is too big, it is truncated and '...' is added to the end. |
| 155 void DrawStringInt(const std::wstring& text, const ChromeFont& font, | 155 void DrawStringInt(const std::wstring& text, const gfx::Font& font, |
| 156 const SkColor& color, int x, int y, int w, int h); | 156 const SkColor& color, int x, int y, int w, int h); |
| 157 | 157 |
| 158 // Draws text with the specified color, font and location. The last argument | 158 // Draws text with the specified color, font and location. The last argument |
| 159 // specifies flags for how the text should be rendered. It can be one of | 159 // specifies flags for how the text should be rendered. It can be one of |
| 160 // TEXT_ALIGN_CENTER, TEXT_ALIGN_RIGHT or TEXT_ALIGN_LEFT. | 160 // TEXT_ALIGN_CENTER, TEXT_ALIGN_RIGHT or TEXT_ALIGN_LEFT. |
| 161 void DrawStringInt(const std::wstring& text, const ChromeFont& font, | 161 void DrawStringInt(const std::wstring& text, const gfx::Font& font, |
| 162 const SkColor& color, int x, int y, int w, int h, | 162 const SkColor& color, int x, int y, int w, int h, |
| 163 int flags); | 163 int flags); |
| 164 | 164 |
| 165 #ifdef OS_WIN // Only implemented on Windows for now. | 165 #ifdef OS_WIN // Only implemented on Windows for now. |
| 166 // Draws text with a 1-pixel halo around it of the given color. It allows | 166 // Draws text with a 1-pixel halo around it of the given color. It allows |
| 167 // ClearType to be drawn to an otherwise transparenct bitmap for drag images. | 167 // ClearType to be drawn to an otherwise transparenct bitmap for drag images. |
| 168 // Drag images have only 1-bit of transparency, so we don't do any fancy | 168 // Drag images have only 1-bit of transparency, so we don't do any fancy |
| 169 // blurring. | 169 // blurring. |
| 170 void DrawStringWithHalo(const std::wstring& text, const ChromeFont& font, | 170 void DrawStringWithHalo(const std::wstring& text, const gfx::Font& font, |
| 171 const SkColor& text_color, const SkColor& halo_color, | 171 const SkColor& text_color, const SkColor& halo_color, |
| 172 int x, int y, int w, int h, int flags); | 172 int x, int y, int w, int h, int flags); |
| 173 #endif | 173 #endif |
| 174 | 174 |
| 175 // Draws a dotted gray rectangle used for focus purposes. | 175 // Draws a dotted gray rectangle used for focus purposes. |
| 176 void DrawFocusRect(int x, int y, int width, int height); | 176 void DrawFocusRect(int x, int y, int width, int height); |
| 177 | 177 |
| 178 // Tiles the image in the specified region. | 178 // Tiles the image in the specified region. |
| 179 void TileImageInt(const SkBitmap& bitmap, int x, int y, int w, int h); | 179 void TileImageInt(const SkBitmap& bitmap, int x, int y, int w, int h); |
| 180 void TileImageInt(const SkBitmap& bitmap, int src_x, int src_y, | 180 void TileImageInt(const SkBitmap& bitmap, int src_x, int src_y, |
| 181 int dest_x, int dest_y, int w, int h); | 181 int dest_x, int dest_y, int w, int h); |
| 182 | 182 |
| 183 // Extracts a bitmap from the contents of this canvas. | 183 // Extracts a bitmap from the contents of this canvas. |
| 184 SkBitmap ExtractBitmap(); | 184 SkBitmap ExtractBitmap(); |
| 185 | 185 |
| 186 #if defined(OS_LINUX) | 186 #if defined(OS_LINUX) |
| 187 // Applies current matrix on the canvas to the cairo context. This should be | 187 // Applies current matrix on the canvas to the cairo context. This should be |
| 188 // invoked anytime you plan on drawing directly to the cairo context. Be | 188 // invoked anytime you plan on drawing directly to the cairo context. Be |
| 189 // sure and set the matrix back to the identity when done. | 189 // sure and set the matrix back to the identity when done. |
| 190 void ApplySkiaMatrixToCairoContext(cairo_t* cr); | 190 void ApplySkiaMatrixToCairoContext(cairo_t* cr); |
| 191 #endif | 191 #endif |
| 192 | 192 |
| 193 // Compute the size required to draw some text with the provided font. | 193 // Compute the size required to draw some text with the provided font. |
| 194 // Attempts to fit the text with the provided width and height. Increases | 194 // Attempts to fit the text with the provided width and height. Increases |
| 195 // height and then width as needed to make the text fit. This method | 195 // height and then width as needed to make the text fit. This method |
| 196 // supports multiple lines. | 196 // supports multiple lines. |
| 197 static void SizeStringInt(const std::wstring& test, const ChromeFont& font, | 197 static void SizeStringInt(const std::wstring& test, const gfx::Font& font, |
| 198 int *width, int* height, int flags); | 198 int *width, int* height, int flags); |
| 199 | 199 |
| 200 private: | 200 private: |
| 201 #if defined(OS_WIN) | 201 #if defined(OS_WIN) |
| 202 // Draws text with the specified color, font and location. The text is | 202 // Draws text with the specified color, font and location. The text is |
| 203 // aligned to the left, vertically centered, clipped to the region. If the | 203 // aligned to the left, vertically centered, clipped to the region. If the |
| 204 // text is too big, it is truncated and '...' is added to the end. | 204 // text is too big, it is truncated and '...' is added to the end. |
| 205 void DrawStringInt(const std::wstring& text, HFONT font, | 205 void DrawStringInt(const std::wstring& text, HFONT font, |
| 206 const SkColor& color, int x, int y, int w, int h, | 206 const SkColor& color, int x, int y, int w, int h, |
| 207 int flags); | 207 int flags); |
| 208 #endif | 208 #endif |
| 209 | 209 |
| 210 DISALLOW_EVIL_CONSTRUCTORS(ChromeCanvas); | 210 DISALLOW_EVIL_CONSTRUCTORS(ChromeCanvas); |
| 211 }; | 211 }; |
| 212 | 212 |
| 213 #if defined(OS_WIN) || defined(OS_LINUX) | 213 #if defined(OS_WIN) || defined(OS_LINUX) |
| 214 typedef skia::CanvasPaintT<ChromeCanvas> ChromeCanvasPaint; | 214 typedef skia::CanvasPaintT<ChromeCanvas> ChromeCanvasPaint; |
| 215 #endif | 215 #endif |
| 216 | 216 |
| 217 #endif // APP_GFX_CHROME_CANVAS_H_ | 217 #endif // APP_GFX_CHROME_CANVAS_H_ |
| OLD | NEW |