Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(49)

Side by Side Diff: ui/gfx/canvas_skia_linux.cc

Issue 7977025: aura: Make 'ui' buildable without gtk. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/gfx/canvas_skia.h ('k') | ui/gfx/insets.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #include "ui/gfx/canvas_skia.h" 5 #include "ui/gfx/canvas_skia.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include <cairo/cairo.h> 9 #include <cairo/cairo.h>
10 #include <gtk/gtk.h>
11 #include <pango/pango.h> 10 #include <pango/pango.h>
12 #include <pango/pangocairo.h> 11 #include <pango/pangocairo.h>
13 12
14 #include "base/i18n/rtl.h" 13 #include "base/i18n/rtl.h"
15 #include "base/logging.h" 14 #include "base/logging.h"
16 #include "ui/gfx/font.h" 15 #include "ui/gfx/font.h"
17 #include "ui/gfx/gtk_util.h"
18 #include "ui/gfx/pango_util.h" 16 #include "ui/gfx/pango_util.h"
19 #include "ui/gfx/platform_font_gtk.h" 17 #include "ui/gfx/platform_font_pango.h"
20 #include "ui/gfx/rect.h" 18 #include "ui/gfx/rect.h"
21 #include "ui/gfx/skia_util.h" 19 #include "ui/gfx/skia_util.h"
22 20
21 #if defined(TOOLKIT_USES_GTK)
22 #include <gdk/gdk.h>
23 #endif
24
23 using std::max; 25 using std::max;
24 26
25 namespace { 27 namespace {
26 28
27 // Multiply by the text height to determine how much text should be faded 29 // Multiply by the text height to determine how much text should be faded
28 // when elliding. 30 // when elliding.
29 const double kFadeWidthFactor = 1.5; 31 const double kFadeWidthFactor = 1.5;
30 32
31 // End state of the elliding fade. 33 // End state of the elliding fade.
32 const double kFadeFinalAlpha = 0.15; 34 const double kFadeFinalAlpha = 0.15;
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 if (font_.GetStyle() & gfx::Font::UNDERLINED) 214 if (font_.GetStyle() & gfx::Font::UNDERLINED)
213 DrawUnderline(text_cr, 0.0); 215 DrawUnderline(text_cr, 0.0);
214 } 216 }
215 217
216 const SkBitmap& text_bitmap = const_cast<SkBitmap&>( 218 const SkBitmap& text_bitmap = const_cast<SkBitmap&>(
217 skia::GetTopDevice(text_canvas)->accessBitmap(false)); 219 skia::GetTopDevice(text_canvas)->accessBitmap(false));
218 canvas_->DrawBitmapInt(text_bitmap, text_x_ - 1, text_y_ - 1); 220 canvas_->DrawBitmapInt(text_bitmap, text_x_ - 1, text_y_ - 1);
219 } 221 }
220 222
221 void DrawStringContext::DrawUnderline(cairo_t* cr, double extra_edge_width) { 223 void DrawStringContext::DrawUnderline(cairo_t* cr, double extra_edge_width) {
222 gfx::PlatformFontGtk* platform_font = 224 gfx::PlatformFontPango* platform_font =
223 static_cast<gfx::PlatformFontGtk*>(font_.platform_font()); 225 static_cast<gfx::PlatformFontPango*>(font_.platform_font());
224 const double underline_y = 226 const double underline_y =
225 static_cast<double>(text_y_) + text_height_ + 227 static_cast<double>(text_y_) + text_height_ +
226 platform_font->underline_position(); 228 platform_font->underline_position();
227 cairo_set_line_width( 229 cairo_set_line_width(
228 cr, platform_font->underline_thickness() + 2 * extra_edge_width); 230 cr, platform_font->underline_thickness() + 2 * extra_edge_width);
229 cairo_move_to(cr, text_x_ - extra_edge_width, underline_y); 231 cairo_move_to(cr, text_x_ - extra_edge_width, underline_y);
230 cairo_line_to(cr, text_x_ + text_width_ + extra_edge_width, underline_y); 232 cairo_line_to(cr, text_x_ + text_width_ + extra_edge_width, underline_y);
231 cairo_stroke(cr); 233 cairo_stroke(cr);
232 } 234 }
233 235
(...skipping 26 matching lines...) Expand all
260 layout, 262 layout,
261 text, 263 text,
262 font, 264 font,
263 *width, 265 *width,
264 base::i18n::GetFirstStrongCharacterDirection(text), 266 base::i18n::GetFirstStrongCharacterDirection(text),
265 flags); 267 flags);
266 268
267 pango_layout_get_pixel_size(layout, width, height); 269 pango_layout_get_pixel_size(layout, width, height);
268 270
269 if (font.GetStyle() & gfx::Font::UNDERLINED) { 271 if (font.GetStyle() & gfx::Font::UNDERLINED) {
270 gfx::PlatformFontGtk* platform_font = 272 gfx::PlatformFontPango* platform_font =
271 static_cast<gfx::PlatformFontGtk*>(font.platform_font()); 273 static_cast<gfx::PlatformFontPango*>(font.platform_font());
272 *height += max(platform_font->underline_position() + 274 *height += max(platform_font->underline_position() +
273 platform_font->underline_thickness(), 0.0); 275 platform_font->underline_thickness(), 0.0);
274 } 276 }
275 277
276 // TODO: If the text is being drawn with a halo, we should also pad each of 278 // TODO: If the text is being drawn with a halo, we should also pad each of
277 // the edges by |kTextHaloWidth|... except haloing is currently a drawing-time 279 // the edges by |kTextHaloWidth|... except haloing is currently a drawing-time
278 // thing, and we don't know how the text will be drawn here. :-( This only 280 // thing, and we don't know how the text will be drawn here. :-( This only
279 // seems to come into play at present if the text is both haloed and 281 // seems to come into play at present if the text is both haloed and
280 // underlined; otherwise, the size returned by Pango is (at least sometimes) 282 // underlined; otherwise, the size returned by Pango is (at least sometimes)
281 // large enough to include the halo. 283 // large enough to include the halo.
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 int x, int y, int w, int h, 324 int x, int y, int w, int h,
323 int flags) { 325 int flags) {
324 if (!IntersectsClipRectInt(x, y, w, h)) 326 if (!IntersectsClipRectInt(x, y, w, h))
325 return; 327 return;
326 328
327 gfx::Rect bounds(x, y, w, h); 329 gfx::Rect bounds(x, y, w, h);
328 DrawStringContext context(this, text, font, bounds, bounds, flags); 330 DrawStringContext context(this, text, font, bounds, bounds, flags);
329 context.Draw(color); 331 context.Draw(color);
330 } 332 }
331 333
334 #if defined(TOOLKIT_USES_GTK)
332 void CanvasSkia::DrawGdkPixbuf(GdkPixbuf* pixbuf, int x, int y) { 335 void CanvasSkia::DrawGdkPixbuf(GdkPixbuf* pixbuf, int x, int y) {
333 if (!pixbuf) { 336 if (!pixbuf) {
334 NOTREACHED(); 337 NOTREACHED();
335 return; 338 return;
336 } 339 }
337 340
338 skia::ScopedPlatformPaint scoped_platform_paint(this); 341 skia::ScopedPlatformPaint scoped_platform_paint(this);
339 cairo_t* cr = scoped_platform_paint.GetPlatformSurface(); 342 cairo_t* cr = scoped_platform_paint.GetPlatformSurface();
340 gdk_cairo_set_source_pixbuf(cr, pixbuf, x, y); 343 gdk_cairo_set_source_pixbuf(cr, pixbuf, x, y);
341 cairo_paint(cr); 344 cairo_paint(cr);
342 } 345 }
346 #endif // defined(TOOLKIT_USES_GTK)
343 347
344 ui::TextureID CanvasSkia::GetTextureID() { 348 ui::TextureID CanvasSkia::GetTextureID() {
345 // TODO(wjmaclean) 349 // TODO(wjmaclean)
346 return 0; 350 return 0;
347 } 351 }
348 352
349 } // namespace gfx 353 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/canvas_skia.h ('k') | ui/gfx/insets.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698