Index: ui/views/widget/native_widget_mac.mm |
diff --git a/ui/views/widget/native_widget_mac.mm b/ui/views/widget/native_widget_mac.mm |
index 16a45e5169835ff44c675fdb4523dd778e117572..55d6074edd03114494deaf53abc448e6dcaccc89 100644 |
--- a/ui/views/widget/native_widget_mac.mm |
+++ b/ui/views/widget/native_widget_mac.mm |
@@ -6,15 +6,82 @@ |
#include <Cocoa/Cocoa.h> |
+#include "base/mac/scoped_nsobject.h" |
+#include "ui/compositor/layer_owner.h" |
#include "ui/gfx/font_list.h" |
+#include "ui/native_theme/native_theme_mac.h" |
+#include "ui/gfx/canvas_paint_mac.h" |
+#include "ui/gfx/mac/point_utils.h" |
+#include "ui/views/cocoa/bridged_content_view.h" |
+ |
+namespace { |
+ |
+template <class OSTREAM> |
+OSTREAM& operator<<(OSTREAM& out, const NSRect& rect) { |
+ CGFloat x = rect.origin.x; |
+ CGFloat y = rect.origin.y; |
+ out << '[' << rect.size.width << 'x' << rect.size.height |
+ << (x < 0 ? '-' : '+') << x << (y < 0 ? '-' : '+') << y << ']'; |
+ return out; |
+} |
+ |
+template <class OSTREAM> |
+OSTREAM& operator<<(OSTREAM& out, const NSPoint& point) { |
+ out << '(' << point.x << ',' << point.y << ')'; |
+ return out; |
+} |
+ |
+} // namespace |
namespace views { |
+class NativeWidgetMac::Impl : public ui::LayerOwner { |
+ public: |
+ Impl() : bridged_view_(nil) {} |
+ virtual ~Impl() {} |
+ |
+ ui::Layer* GetOrCreateLayer() { |
+ if (!bridged_view_) |
+ return NULL; |
+ |
+ if (layer()) |
+ return layer(); |
+ |
+ DCHECK(!compositor_); |
+ compositor_.reset(new ui::Compositor(bridged_view_)); |
+ SetLayer(new ui::Layer(ui::LAYER_TEXTURED)); |
+ compositor_->SetRootLayer(layer()); |
+ return layer(); |
+ } |
+ |
+ void SetRootView(views::View* view) { |
+ if (view == [bridged_view_ view]) |
+ return; |
+ |
+ DCHECK(!compositor_); |
+ [bridged_view_ clearView]; |
+ bridged_view_.reset(); |
+ if (view) |
+ bridged_view_.reset([[BridgedContentView alloc] initWithView:view]); |
+ } |
+ |
+ NSView* GetNSView() { return bridged_view_; } |
+ |
+ private: |
+ friend class NativeWidgetMac; |
+ |
+ base::scoped_nsobject<BridgedContentView> bridged_view_; |
+ scoped_ptr<ui::Compositor> compositor_; |
+ base::scoped_nsobject<NSWindow> window_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(Impl); |
+}; |
+ |
//////////////////////////////////////////////////////////////////////////////// |
// NativeWidgetMac, public: |
NativeWidgetMac::NativeWidgetMac(internal::NativeWidgetDelegate* delegate) |
- : delegate_(delegate), window_(nil) { |
+ : delegate_(delegate), impl_(new Impl) { |
} |
NativeWidgetMac::~NativeWidgetMac() { |
@@ -30,10 +97,11 @@ void NativeWidgetMac::InitNativeWidget(const Widget::InitParams& params) { |
// TODO(tapted): Determine a good initial style mask from |params|. |
NSInteger style_mask = NSTitledWindowMask | NSClosableWindowMask | |
NSMiniaturizableWindowMask | NSResizableWindowMask; |
- window_.reset([[NSWindow alloc] initWithContentRect:content_rect |
- styleMask:style_mask |
- backing:NSBackingStoreBuffered |
- defer:NO]); |
+ impl_->window_.reset( |
+ [[NSWindow alloc] initWithContentRect:content_rect |
+ styleMask:style_mask |
+ backing:NSBackingStoreBuffered |
+ defer:NO]); |
} |
NonClientFrameView* NativeWidgetMac::CreateNonClientFrameView() { |
@@ -62,11 +130,11 @@ const Widget* NativeWidgetMac::GetWidget() const { |
} |
gfx::NativeView NativeWidgetMac::GetNativeView() const { |
- return [window_ contentView]; |
+ return [impl_->window_ contentView]; |
} |
gfx::NativeWindow NativeWidgetMac::GetNativeWindow() const { |
- return window_; |
+ return impl_->window_; |
} |
Widget* NativeWidgetMac::GetTopLevelWidget() { |
@@ -76,20 +144,23 @@ Widget* NativeWidgetMac::GetTopLevelWidget() { |
const ui::Compositor* NativeWidgetMac::GetCompositor() const { |
NOTIMPLEMENTED(); |
- return NULL; |
+ return impl_->layer() ? impl_->layer()->GetCompositor() : NULL; |
} |
ui::Compositor* NativeWidgetMac::GetCompositor() { |
NOTIMPLEMENTED(); |
- return NULL; |
+ return impl_->layer() ? impl_->layer()->GetCompositor() : NULL; |
} |
ui::Layer* NativeWidgetMac::GetLayer() { |
NOTIMPLEMENTED(); |
return NULL; |
+ //return impl_->GetOrCreateLayer(); |
} |
void NativeWidgetMac::ReorderNativeViews() { |
+ impl_->SetRootView(GetWidget()->GetRootView()); |
+ [impl_->window_ setContentView:impl_->GetNSView()]; |
NOTIMPLEMENTED(); |
} |
@@ -178,11 +249,13 @@ gfx::Rect NativeWidgetMac::GetRestoredBounds() const { |
} |
void NativeWidgetMac::SetBounds(const gfx::Rect& bounds) { |
- NOTIMPLEMENTED(); |
+ NSRect frame_rect = |
+ [impl_->window_ frameRectForContentRect:gfx::ScreenRectToNSRect(bounds)]; |
+ [impl_->window_ setFrame:frame_rect display:YES animate:NO]; |
} |
void NativeWidgetMac::SetSize(const gfx::Size& size) { |
- [window_ setContentSize:NSMakeSize(size.width(), size.height())]; |
+ [impl_->window_ setContentSize:NSMakeSize(size.width(), size.height())]; |
} |
void NativeWidgetMac::StackAbove(gfx::NativeView native_view) { |
@@ -224,6 +297,7 @@ void NativeWidgetMac::ShowMaximizedWithBounds( |
void NativeWidgetMac::ShowWithWindowState(ui::WindowShowState state) { |
NOTIMPLEMENTED(); |
+ Activate(); |
} |
bool NativeWidgetMac::IsVisible() const { |
@@ -232,7 +306,8 @@ bool NativeWidgetMac::IsVisible() const { |
} |
void NativeWidgetMac::Activate() { |
- NOTIMPLEMENTED(); |
+ [impl_->window_ makeKeyAndOrderFront:nil]; |
+ [NSApp activateIgnoringOtherApps:YES]; |
} |
void NativeWidgetMac::Deactivate() { |
@@ -241,7 +316,7 @@ void NativeWidgetMac::Deactivate() { |
bool NativeWidgetMac::IsActive() const { |
NOTIMPLEMENTED(); |
- return true; |
+ return false; |
} |
void NativeWidgetMac::SetAlwaysOnTop(bool always_on_top) { |
@@ -309,6 +384,10 @@ void NativeWidgetMac::RunShellDrag(View* view, |
} |
void NativeWidgetMac::SchedulePaintInRect(const gfx::Rect& rect) { |
+ DLOG(INFO) << "SchedulePaintInRect"; |
+ [impl_->GetNSView() setNeedsDisplay:YES]; |
+ if (impl_->layer()) |
+ impl_->layer()->SchedulePaint(rect); |
NOTIMPLEMENTED(); |
} |
@@ -347,8 +426,7 @@ void NativeWidgetMac::SetVisibilityChangedAnimationsEnabled(bool value) { |
} |
ui::NativeTheme* NativeWidgetMac::GetNativeTheme() const { |
- NOTIMPLEMENTED(); |
- return NULL; |
+ return ui::NativeTheme::instance(); |
} |
void NativeWidgetMac::OnRootViewLayout() const { |
@@ -379,8 +457,8 @@ namespace internal { |
// static |
NativeWidgetPrivate* NativeWidgetPrivate::CreateNativeWidget( |
internal::NativeWidgetDelegate* delegate) { |
- NOTIMPLEMENTED(); |
- return NULL; |
+ // Called e.g. via CreateBubbleWidget(). |
+ return new NativeWidgetMac(delegate); |
} |
// static |