diff options
Diffstat (limited to 'chromium/ui/views/cocoa/bridged_content_view.mm')
-rw-r--r-- | chromium/ui/views/cocoa/bridged_content_view.mm | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/chromium/ui/views/cocoa/bridged_content_view.mm b/chromium/ui/views/cocoa/bridged_content_view.mm new file mode 100644 index 00000000000..bd9a511a244 --- /dev/null +++ b/chromium/ui/views/cocoa/bridged_content_view.mm @@ -0,0 +1,50 @@ +// Copyright 2014 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 "ui/views/cocoa/bridged_content_view.h" + +#include "base/logging.h" +#include "ui/gfx/canvas_paint_mac.h" +#include "ui/views/view.h" + +@implementation BridgedContentView + +@synthesize hostedView = hostedView_; + +- (id)initWithView:(views::View*)viewToHost { + DCHECK(viewToHost); + gfx::Rect bounds = viewToHost->bounds(); + // To keep things simple, assume the origin is (0, 0) until there exists a use + // case for something other than that. + DCHECK(bounds.origin().IsOrigin()); + NSRect initialFrame = NSMakeRect(0, 0, bounds.width(), bounds.height()); + if ((self = [super initWithFrame:initialFrame])) + hostedView_ = viewToHost; + + return self; +} + +- (void)clearView { + hostedView_ = NULL; +} + +// NSView implementation. + +- (void)setFrameSize:(NSSize)newSize { + [super setFrameSize:newSize]; + if (!hostedView_) + return; + + hostedView_->SetSize(gfx::Size(newSize.width, newSize.height)); +} + +- (void)drawRect:(NSRect)dirtyRect { + if (!hostedView_) + return; + + gfx::CanvasSkiaPaint canvas(dirtyRect, false /* opaque */); + hostedView_->Paint(&canvas, views::CullSet()); +} + +@end |