diff options
author | amanda@chromium.org <amanda@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-11 01:57:28 +0000 |
---|---|---|
committer | amanda@chromium.org <amanda@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-11 01:57:28 +0000 |
commit | 6bf1a81cdfcc48f20cf53c2601f4456f2d9d30ef (patch) | |
tree | 7bedf19228a20b83189ab96e617e72210991c7c4 /app | |
parent | 7e05f6c4baad4f81e06835b83febe2784568ebe1 (diff) | |
download | chromium_src-6bf1a81cdfcc48f20cf53c2601f4456f2d9d30ef.zip chromium_src-6bf1a81cdfcc48f20cf53c2601f4456f2d9d30ef.tar.gz chromium_src-6bf1a81cdfcc48f20cf53c2601f4456f2d9d30ef.tar.bz2 |
Wire up windowless plugins. Mostly Mac related, some cross
platform aspects.
BUG=10809
TEST=none
Review URL: http://codereview.chromium.org/113637
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20453 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app')
-rw-r--r-- | app/app.gyp | 1 | ||||
-rw-r--r-- | app/gfx/canvas.cc | 10 | ||||
-rw-r--r-- | app/gfx/canvas_mac.mm | 79 |
3 files changed, 80 insertions, 10 deletions
diff --git a/app/app.gyp b/app/app.gyp index faced76..5c989ae 100644 --- a/app/app.gyp +++ b/app/app.gyp @@ -68,6 +68,7 @@ 'gfx/canvas.cc', 'gfx/canvas.h', 'gfx/canvas_linux.cc', + 'gfx/canvas_mac.mm', 'gfx/canvas_win.cc', 'gfx/font.h', 'gfx/font_gtk.cc', diff --git a/app/gfx/canvas.cc b/app/gfx/canvas.cc index d3b55ab..2cef3de 100644 --- a/app/gfx/canvas.cc +++ b/app/gfx/canvas.cc @@ -221,16 +221,6 @@ void Canvas::DrawStringInt(const std::wstring& text, l10n_util::DefaultCanvasTextAlignment()); } -#if defined(OS_MACOSX) -void Canvas::DrawStringInt(const std::wstring& text, - const gfx::Font& font, - const SkColor& color, - int x, int y, int w, int h, - int flags) { - NOTIMPLEMENTED(); -} -#endif - void Canvas::TileImageInt(const SkBitmap& bitmap, int x, int y, int w, int h) { TileImageInt(bitmap, 0, 0, x, y, w, h); } diff --git a/app/gfx/canvas_mac.mm b/app/gfx/canvas_mac.mm new file mode 100644 index 0000000..b766b32 --- /dev/null +++ b/app/gfx/canvas_mac.mm @@ -0,0 +1,79 @@ +// 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. + +#import <Cocoa/Cocoa.h> + +#include "app/gfx/canvas.h" + +#include "app/gfx/font.h" +#include "app/l10n_util.h" +#include "base/gfx/rect.h" +#include "base/scoped_cftyperef.h" +#include "base/sys_string_conversions.h" +#include "third_party/skia/include/core/SkShader.h" + +namespace gfx { + +Canvas::Canvas(int width, int height, bool is_opaque) + : skia::PlatformCanvas(width, height, is_opaque) { +} + +Canvas::Canvas() : skia::PlatformCanvas() { +} + +Canvas::~Canvas() { +} + +// static +void Canvas::SizeStringInt(const std::wstring& text, + const gfx::Font& font, + int *width, int *height, int flags) { + *width = font.GetStringWidth(text); + *height = font.height(); +} + +void Canvas::DrawStringInt(const std::wstring& text, const gfx::Font& font, + const SkColor& color, int x, int y, int w, int h, + int flags) { + if (!IntersectsClipRectInt(x, y, w, h)) + return; + + CGContextRef context = beginPlatformPaint(); + CGContextSaveGState(context); + + NSColor* ns_color = [NSColor colorWithDeviceRed:SkColorGetR(color) / 255.0 + green:SkColorGetG(color) / 255.0 + blue:SkColorGetB(color) / 255.0 + alpha:1.0]; + NSMutableParagraphStyle *ns_style = + [[[NSParagraphStyle alloc] init] autorelease]; + if (flags & TEXT_ALIGN_CENTER) + [ns_style setAlignment:NSCenterTextAlignment]; + // TODO(awalker): Implement the rest of the Canvas text flags + + NSDictionary* attributes = + [NSDictionary dictionaryWithObjectsAndKeys: + font.nativeFont(), NSFontAttributeName, + ns_color, NSForegroundColorAttributeName, + ns_style, NSParagraphStyleAttributeName, + nil]; + + NSAttributedString* ns_string = + [[[NSAttributedString alloc] initWithString:base::SysWideToNSString(text) + attributes:attributes] autorelease]; + scoped_cftyperef<CTFramesetterRef> framesetter( + CTFramesetterCreateWithAttributedString(reinterpret_cast<CFAttributedStringRef>(ns_string))); + + CGRect text_bounds = CGRectMake(x, y, w, h); + CGMutablePathRef path = CGPathCreateMutable(); + CGPathAddRect(path, NULL, text_bounds); + + scoped_cftyperef<CTFrameRef> frame( + CTFramesetterCreateFrame(framesetter, CFRangeMake(0, 0), path, NULL)); + CTFrameDraw(frame, context); + CGContextRestoreGState(context); + endPlatformPaint(); +} + +} // namespace gfx |