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

Side by Side Diff: ui/views/widget/native_widget_mac.mm

Issue 303543004: MacViews: views_examples_with_content_exe working! Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add files Created 6 years, 6 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/views/widget/native_widget_mac.h" 5 #include "ui/views/widget/native_widget_mac.h"
6 6
7 #include <Cocoa/Cocoa.h> 7 #include <Cocoa/Cocoa.h>
8 8
9 #include "base/mac/scoped_nsobject.h"
10 #include "ui/compositor/layer_owner.h"
9 #include "ui/gfx/font_list.h" 11 #include "ui/gfx/font_list.h"
12 #include "ui/native_theme/native_theme_mac.h"
13 #include "ui/gfx/canvas_paint_mac.h"
14 #include "ui/gfx/mac/point_utils.h"
15 #include "ui/views/cocoa/bridged_content_view.h"
16
17 namespace {
18
19 template <class OSTREAM>
20 OSTREAM& operator<<(OSTREAM& out, const NSRect& rect) {
21 CGFloat x = rect.origin.x;
22 CGFloat y = rect.origin.y;
23 out << '[' << rect.size.width << 'x' << rect.size.height
24 << (x < 0 ? '-' : '+') << x << (y < 0 ? '-' : '+') << y << ']';
25 return out;
26 }
27
28 template <class OSTREAM>
29 OSTREAM& operator<<(OSTREAM& out, const NSPoint& point) {
30 out << '(' << point.x << ',' << point.y << ')';
31 return out;
32 }
33
34 } // namespace
10 35
11 namespace views { 36 namespace views {
12 37
38 class NativeWidgetMac::Impl : public ui::LayerOwner {
39 public:
40 Impl() : bridged_view_(nil) {}
41 virtual ~Impl() {}
42
43 ui::Layer* GetOrCreateLayer() {
44 if (!bridged_view_)
45 return NULL;
46
47 if (layer())
48 return layer();
49
50 DCHECK(!compositor_);
51 compositor_.reset(new ui::Compositor(bridged_view_));
52 SetLayer(new ui::Layer(ui::LAYER_TEXTURED));
53 compositor_->SetRootLayer(layer());
54 return layer();
55 }
56
57 void SetRootView(views::View* view) {
58 if (view == [bridged_view_ view])
59 return;
60
61 DCHECK(!compositor_);
62 [bridged_view_ clearView];
63 bridged_view_.reset();
64 if (view)
65 bridged_view_.reset([[BridgedContentView alloc] initWithView:view]);
66 }
67
68 NSView* GetNSView() { return bridged_view_; }
69
70 private:
71 friend class NativeWidgetMac;
72
73 base::scoped_nsobject<BridgedContentView> bridged_view_;
74 scoped_ptr<ui::Compositor> compositor_;
75 base::scoped_nsobject<NSWindow> window_;
76
77 DISALLOW_COPY_AND_ASSIGN(Impl);
78 };
79
13 //////////////////////////////////////////////////////////////////////////////// 80 ////////////////////////////////////////////////////////////////////////////////
14 // NativeWidgetMac, public: 81 // NativeWidgetMac, public:
15 82
16 NativeWidgetMac::NativeWidgetMac(internal::NativeWidgetDelegate* delegate) 83 NativeWidgetMac::NativeWidgetMac(internal::NativeWidgetDelegate* delegate)
17 : delegate_(delegate), window_(nil) { 84 : delegate_(delegate), impl_(new Impl) {
18 } 85 }
19 86
20 NativeWidgetMac::~NativeWidgetMac() { 87 NativeWidgetMac::~NativeWidgetMac() {
21 } 88 }
22 89
23 //////////////////////////////////////////////////////////////////////////////// 90 ////////////////////////////////////////////////////////////////////////////////
24 // NativeWidgetMac, internal::NativeWidgetPrivate implementation: 91 // NativeWidgetMac, internal::NativeWidgetPrivate implementation:
25 92
26 void NativeWidgetMac::InitNativeWidget(const Widget::InitParams& params) { 93 void NativeWidgetMac::InitNativeWidget(const Widget::InitParams& params) {
27 // TODO(tapted): Convert position into Cocoa's flipped coordinate space. 94 // TODO(tapted): Convert position into Cocoa's flipped coordinate space.
28 NSRect content_rect = 95 NSRect content_rect =
29 NSMakeRect(0, 0, params.bounds.width(), params.bounds.height()); 96 NSMakeRect(0, 0, params.bounds.width(), params.bounds.height());
30 // TODO(tapted): Determine a good initial style mask from |params|. 97 // TODO(tapted): Determine a good initial style mask from |params|.
31 NSInteger style_mask = NSTitledWindowMask | NSClosableWindowMask | 98 NSInteger style_mask = NSTitledWindowMask | NSClosableWindowMask |
32 NSMiniaturizableWindowMask | NSResizableWindowMask; 99 NSMiniaturizableWindowMask | NSResizableWindowMask;
33 window_.reset([[NSWindow alloc] initWithContentRect:content_rect 100 impl_->window_.reset(
34 styleMask:style_mask 101 [[NSWindow alloc] initWithContentRect:content_rect
35 backing:NSBackingStoreBuffered 102 styleMask:style_mask
36 defer:NO]); 103 backing:NSBackingStoreBuffered
104 defer:NO]);
37 } 105 }
38 106
39 NonClientFrameView* NativeWidgetMac::CreateNonClientFrameView() { 107 NonClientFrameView* NativeWidgetMac::CreateNonClientFrameView() {
40 return NULL; 108 return NULL;
41 } 109 }
42 110
43 bool NativeWidgetMac::ShouldUseNativeFrame() const { 111 bool NativeWidgetMac::ShouldUseNativeFrame() const {
44 return false; 112 return false;
45 } 113 }
46 114
47 bool NativeWidgetMac::ShouldWindowContentsBeTransparent() const { 115 bool NativeWidgetMac::ShouldWindowContentsBeTransparent() const {
48 NOTIMPLEMENTED(); 116 NOTIMPLEMENTED();
49 return false; 117 return false;
50 } 118 }
51 119
52 void NativeWidgetMac::FrameTypeChanged() { 120 void NativeWidgetMac::FrameTypeChanged() {
53 NOTIMPLEMENTED(); 121 NOTIMPLEMENTED();
54 } 122 }
55 123
56 Widget* NativeWidgetMac::GetWidget() { 124 Widget* NativeWidgetMac::GetWidget() {
57 return delegate_->AsWidget(); 125 return delegate_->AsWidget();
58 } 126 }
59 127
60 const Widget* NativeWidgetMac::GetWidget() const { 128 const Widget* NativeWidgetMac::GetWidget() const {
61 return delegate_->AsWidget(); 129 return delegate_->AsWidget();
62 } 130 }
63 131
64 gfx::NativeView NativeWidgetMac::GetNativeView() const { 132 gfx::NativeView NativeWidgetMac::GetNativeView() const {
65 return [window_ contentView]; 133 return [impl_->window_ contentView];
66 } 134 }
67 135
68 gfx::NativeWindow NativeWidgetMac::GetNativeWindow() const { 136 gfx::NativeWindow NativeWidgetMac::GetNativeWindow() const {
69 return window_; 137 return impl_->window_;
70 } 138 }
71 139
72 Widget* NativeWidgetMac::GetTopLevelWidget() { 140 Widget* NativeWidgetMac::GetTopLevelWidget() {
73 NOTIMPLEMENTED(); 141 NOTIMPLEMENTED();
74 return GetWidget(); 142 return GetWidget();
75 } 143 }
76 144
77 const ui::Compositor* NativeWidgetMac::GetCompositor() const { 145 const ui::Compositor* NativeWidgetMac::GetCompositor() const {
78 NOTIMPLEMENTED(); 146 NOTIMPLEMENTED();
79 return NULL; 147 return impl_->layer() ? impl_->layer()->GetCompositor() : NULL;
80 } 148 }
81 149
82 ui::Compositor* NativeWidgetMac::GetCompositor() { 150 ui::Compositor* NativeWidgetMac::GetCompositor() {
83 NOTIMPLEMENTED(); 151 NOTIMPLEMENTED();
84 return NULL; 152 return impl_->layer() ? impl_->layer()->GetCompositor() : NULL;
85 } 153 }
86 154
87 ui::Layer* NativeWidgetMac::GetLayer() { 155 ui::Layer* NativeWidgetMac::GetLayer() {
88 NOTIMPLEMENTED(); 156 NOTIMPLEMENTED();
89 return NULL; 157 return NULL;
158 //return impl_->GetOrCreateLayer();
90 } 159 }
91 160
92 void NativeWidgetMac::ReorderNativeViews() { 161 void NativeWidgetMac::ReorderNativeViews() {
162 impl_->SetRootView(GetWidget()->GetRootView());
163 [impl_->window_ setContentView:impl_->GetNSView()];
93 NOTIMPLEMENTED(); 164 NOTIMPLEMENTED();
94 } 165 }
95 166
96 void NativeWidgetMac::ViewRemoved(View* view) { 167 void NativeWidgetMac::ViewRemoved(View* view) {
97 NOTIMPLEMENTED(); 168 NOTIMPLEMENTED();
98 } 169 }
99 170
100 void NativeWidgetMac::SetNativeWindowProperty(const char* name, void* value) { 171 void NativeWidgetMac::SetNativeWindowProperty(const char* name, void* value) {
101 NOTIMPLEMENTED(); 172 NOTIMPLEMENTED();
102 } 173 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 NOTIMPLEMENTED(); 242 NOTIMPLEMENTED();
172 return gfx::Rect(); 243 return gfx::Rect();
173 } 244 }
174 245
175 gfx::Rect NativeWidgetMac::GetRestoredBounds() const { 246 gfx::Rect NativeWidgetMac::GetRestoredBounds() const {
176 NOTIMPLEMENTED(); 247 NOTIMPLEMENTED();
177 return gfx::Rect(); 248 return gfx::Rect();
178 } 249 }
179 250
180 void NativeWidgetMac::SetBounds(const gfx::Rect& bounds) { 251 void NativeWidgetMac::SetBounds(const gfx::Rect& bounds) {
181 NOTIMPLEMENTED(); 252 NSRect frame_rect =
253 [impl_->window_ frameRectForContentRect:gfx::ScreenRectToNSRect(bounds)];
254 [impl_->window_ setFrame:frame_rect display:YES animate:NO];
182 } 255 }
183 256
184 void NativeWidgetMac::SetSize(const gfx::Size& size) { 257 void NativeWidgetMac::SetSize(const gfx::Size& size) {
185 [window_ setContentSize:NSMakeSize(size.width(), size.height())]; 258 [impl_->window_ setContentSize:NSMakeSize(size.width(), size.height())];
186 } 259 }
187 260
188 void NativeWidgetMac::StackAbove(gfx::NativeView native_view) { 261 void NativeWidgetMac::StackAbove(gfx::NativeView native_view) {
189 NOTIMPLEMENTED(); 262 NOTIMPLEMENTED();
190 } 263 }
191 264
192 void NativeWidgetMac::StackAtTop() { 265 void NativeWidgetMac::StackAtTop() {
193 NOTIMPLEMENTED(); 266 NOTIMPLEMENTED();
194 } 267 }
195 268
(...skipping 21 matching lines...) Expand all
217 NOTIMPLEMENTED(); 290 NOTIMPLEMENTED();
218 } 291 }
219 292
220 void NativeWidgetMac::ShowMaximizedWithBounds( 293 void NativeWidgetMac::ShowMaximizedWithBounds(
221 const gfx::Rect& restored_bounds) { 294 const gfx::Rect& restored_bounds) {
222 NOTIMPLEMENTED(); 295 NOTIMPLEMENTED();
223 } 296 }
224 297
225 void NativeWidgetMac::ShowWithWindowState(ui::WindowShowState state) { 298 void NativeWidgetMac::ShowWithWindowState(ui::WindowShowState state) {
226 NOTIMPLEMENTED(); 299 NOTIMPLEMENTED();
300 Activate();
227 } 301 }
228 302
229 bool NativeWidgetMac::IsVisible() const { 303 bool NativeWidgetMac::IsVisible() const {
230 NOTIMPLEMENTED(); 304 NOTIMPLEMENTED();
231 return true; 305 return true;
232 } 306 }
233 307
234 void NativeWidgetMac::Activate() { 308 void NativeWidgetMac::Activate() {
235 NOTIMPLEMENTED(); 309 [impl_->window_ makeKeyAndOrderFront:nil];
310 [NSApp activateIgnoringOtherApps:YES];
236 } 311 }
237 312
238 void NativeWidgetMac::Deactivate() { 313 void NativeWidgetMac::Deactivate() {
239 NOTIMPLEMENTED(); 314 NOTIMPLEMENTED();
240 } 315 }
241 316
242 bool NativeWidgetMac::IsActive() const { 317 bool NativeWidgetMac::IsActive() const {
243 NOTIMPLEMENTED(); 318 NOTIMPLEMENTED();
244 return true; 319 return false;
245 } 320 }
246 321
247 void NativeWidgetMac::SetAlwaysOnTop(bool always_on_top) { 322 void NativeWidgetMac::SetAlwaysOnTop(bool always_on_top) {
248 NOTIMPLEMENTED(); 323 NOTIMPLEMENTED();
249 } 324 }
250 325
251 bool NativeWidgetMac::IsAlwaysOnTop() const { 326 bool NativeWidgetMac::IsAlwaysOnTop() const {
252 NOTIMPLEMENTED(); 327 NOTIMPLEMENTED();
253 return false; 328 return false;
254 } 329 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 377
303 void NativeWidgetMac::RunShellDrag(View* view, 378 void NativeWidgetMac::RunShellDrag(View* view,
304 const ui::OSExchangeData& data, 379 const ui::OSExchangeData& data,
305 const gfx::Point& location, 380 const gfx::Point& location,
306 int operation, 381 int operation,
307 ui::DragDropTypes::DragEventSource source) { 382 ui::DragDropTypes::DragEventSource source) {
308 NOTIMPLEMENTED(); 383 NOTIMPLEMENTED();
309 } 384 }
310 385
311 void NativeWidgetMac::SchedulePaintInRect(const gfx::Rect& rect) { 386 void NativeWidgetMac::SchedulePaintInRect(const gfx::Rect& rect) {
387 DLOG(INFO) << "SchedulePaintInRect";
388 [impl_->GetNSView() setNeedsDisplay:YES];
389 if (impl_->layer())
390 impl_->layer()->SchedulePaint(rect);
312 NOTIMPLEMENTED(); 391 NOTIMPLEMENTED();
313 } 392 }
314 393
315 void NativeWidgetMac::SetCursor(gfx::NativeCursor cursor) { 394 void NativeWidgetMac::SetCursor(gfx::NativeCursor cursor) {
316 NOTIMPLEMENTED(); 395 NOTIMPLEMENTED();
317 } 396 }
318 397
319 bool NativeWidgetMac::IsMouseEventsEnabled() const { 398 bool NativeWidgetMac::IsMouseEventsEnabled() const {
320 NOTIMPLEMENTED(); 399 NOTIMPLEMENTED();
321 return true; 400 return true;
(...skipping 18 matching lines...) Expand all
340 419
341 void NativeWidgetMac::EndMoveLoop() { 420 void NativeWidgetMac::EndMoveLoop() {
342 NOTIMPLEMENTED(); 421 NOTIMPLEMENTED();
343 } 422 }
344 423
345 void NativeWidgetMac::SetVisibilityChangedAnimationsEnabled(bool value) { 424 void NativeWidgetMac::SetVisibilityChangedAnimationsEnabled(bool value) {
346 NOTIMPLEMENTED(); 425 NOTIMPLEMENTED();
347 } 426 }
348 427
349 ui::NativeTheme* NativeWidgetMac::GetNativeTheme() const { 428 ui::NativeTheme* NativeWidgetMac::GetNativeTheme() const {
350 NOTIMPLEMENTED(); 429 return ui::NativeTheme::instance();
351 return NULL;
352 } 430 }
353 431
354 void NativeWidgetMac::OnRootViewLayout() const { 432 void NativeWidgetMac::OnRootViewLayout() const {
355 NOTIMPLEMENTED(); 433 NOTIMPLEMENTED();
356 } 434 }
357 435
358 //////////////////////////////////////////////////////////////////////////////// 436 ////////////////////////////////////////////////////////////////////////////////
359 // NativeWidgetMac, NativeWidget implementation: 437 // NativeWidgetMac, NativeWidget implementation:
360 438
361 ui::EventHandler* NativeWidgetMac::GetEventHandler() { 439 ui::EventHandler* NativeWidgetMac::GetEventHandler() {
(...skipping 10 matching lines...) Expand all
372 } 450 }
373 451
374 namespace internal { 452 namespace internal {
375 453
376 //////////////////////////////////////////////////////////////////////////////// 454 ////////////////////////////////////////////////////////////////////////////////
377 // internal::NativeWidgetPrivate, public: 455 // internal::NativeWidgetPrivate, public:
378 456
379 // static 457 // static
380 NativeWidgetPrivate* NativeWidgetPrivate::CreateNativeWidget( 458 NativeWidgetPrivate* NativeWidgetPrivate::CreateNativeWidget(
381 internal::NativeWidgetDelegate* delegate) { 459 internal::NativeWidgetDelegate* delegate) {
382 NOTIMPLEMENTED(); 460 // Called e.g. via CreateBubbleWidget().
383 return NULL; 461 return new NativeWidgetMac(delegate);
384 } 462 }
385 463
386 // static 464 // static
387 NativeWidgetPrivate* NativeWidgetPrivate::GetNativeWidgetForNativeView( 465 NativeWidgetPrivate* NativeWidgetPrivate::GetNativeWidgetForNativeView(
388 gfx::NativeView native_view) { 466 gfx::NativeView native_view) {
389 NOTIMPLEMENTED(); 467 NOTIMPLEMENTED();
390 return NULL; 468 return NULL;
391 } 469 }
392 470
393 // static 471 // static
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 } 513 }
436 514
437 // static 515 // static
438 gfx::FontList NativeWidgetPrivate::GetWindowTitleFontList() { 516 gfx::FontList NativeWidgetPrivate::GetWindowTitleFontList() {
439 NOTIMPLEMENTED(); 517 NOTIMPLEMENTED();
440 return gfx::FontList(); 518 return gfx::FontList();
441 } 519 }
442 520
443 } // namespace internal 521 } // namespace internal
444 } // namespace views 522 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/widget/native_widget_mac.h ('k') | ui/views_content_client/views_content_browser_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698