Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/shell/shell.h" | 5 #include "content/shell/shell.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #import "base/mac/cocoa_protocols.h" | 10 #import "base/mac/cocoa_protocols.h" |
| 11 #import "base/memory/scoped_nsobject.h" | 11 #import "base/memory/scoped_nsobject.h" |
| 12 #include "base/string_piece.h" | 12 #include "base/string_piece.h" |
| 13 #include "base/sys_string_conversions.h" | 13 #include "base/sys_string_conversions.h" |
| 14 #import "content/public/browser/accelerated_window_interface.h" | |
| 15 #include "content/public/browser/native_web_keyboard_event.h" | 14 #include "content/public/browser/native_web_keyboard_event.h" |
| 16 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
| 17 #include "content/public/browser/web_contents_view.h" | 16 #include "content/public/browser/web_contents_view.h" |
| 18 #include "content/shell/resource.h" | 17 #include "content/shell/resource.h" |
| 19 #include "googleurl/src/gurl.h" | 18 #include "googleurl/src/gurl.h" |
| 20 | 19 #import "ui/base/cocoa/underlay_opengl_hosting_window.h" |
| 21 @interface ShellWindow : NSWindow<UnderlayableSurface> { | |
| 22 @private | |
| 23 int underlaySurfaceCount_; | |
| 24 } | |
| 25 | |
| 26 // Informs the window that an underlay surface has been added/removed. The | |
| 27 // window is non-opaque while underlay surfaces are present. | |
| 28 - (void)underlaySurfaceAdded; | |
| 29 - (void)underlaySurfaceRemoved; | |
| 30 | |
| 31 @end | |
| 32 | |
| 33 @implementation ShellWindow | |
| 34 | |
| 35 - (void)underlaySurfaceAdded { | |
| 36 DCHECK_GE(underlaySurfaceCount_, 0); | |
| 37 ++underlaySurfaceCount_; | |
| 38 | |
| 39 // We're having the OpenGL surface render under the window, so the window | |
| 40 // needs to be not opaque. | |
| 41 if (underlaySurfaceCount_ == 1) | |
| 42 [self setOpaque:NO]; | |
| 43 } | |
| 44 | |
| 45 - (void)underlaySurfaceRemoved { | |
| 46 --underlaySurfaceCount_; | |
| 47 DCHECK_GE(underlaySurfaceCount_, 0); | |
| 48 | |
| 49 if (underlaySurfaceCount_ == 0) | |
| 50 [self setOpaque:YES]; | |
| 51 } | |
| 52 | |
| 53 @end | |
| 54 | 20 |
|
Avi (use Gerrit)
2012/04/02 20:55:20
Yes!
| |
| 55 // Receives notification that the window is closing so that it can start the | 21 // Receives notification that the window is closing so that it can start the |
| 56 // tear-down process. Is responsible for deleting itself when done. | 22 // tear-down process. Is responsible for deleting itself when done. |
| 57 @interface ContentShellWindowDelegate : NSObject<NSWindowDelegate> { | 23 @interface ContentShellWindowDelegate : NSObject<NSWindowDelegate> { |
| 58 @private | 24 @private |
| 59 content::Shell* shell_; | 25 content::Shell* shell_; |
| 60 } | 26 } |
| 61 - (id)initWithShell:(content::Shell*)shell; | 27 - (id)initWithShell:(content::Shell*)shell; |
| 62 @end | 28 @end |
| 63 | 29 |
| 64 @implementation ContentShellWindowDelegate | 30 @implementation ContentShellWindowDelegate |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 170 void Shell::PlatformSetAddressBarURL(const GURL& url) { | 136 void Shell::PlatformSetAddressBarURL(const GURL& url) { |
| 171 NSString* url_string = base::SysUTF8ToNSString(url.spec()); | 137 NSString* url_string = base::SysUTF8ToNSString(url.spec()); |
| 172 [url_edit_view_ setStringValue:url_string]; | 138 [url_edit_view_ setStringValue:url_string]; |
| 173 } | 139 } |
| 174 | 140 |
| 175 void Shell::PlatformSetIsLoading(bool loading) { | 141 void Shell::PlatformSetIsLoading(bool loading) { |
| 176 } | 142 } |
| 177 | 143 |
| 178 void Shell::PlatformCreateWindow(int width, int height) { | 144 void Shell::PlatformCreateWindow(int width, int height) { |
| 179 NSRect initial_window_bounds = NSMakeRect(0, 0, width, height); | 145 NSRect initial_window_bounds = NSMakeRect(0, 0, width, height); |
| 180 window_ = | 146 window_ = [[UnderlayOpenGLHostingWindow alloc] |
| 181 [[ShellWindow alloc] initWithContentRect:initial_window_bounds | 147 initWithContentRect:initial_window_bounds |
| 182 styleMask:(NSTitledWindowMask | | 148 styleMask:(NSTitledWindowMask | |
| 183 NSClosableWindowMask | | 149 NSClosableWindowMask | |
| 184 NSMiniaturizableWindowMask | | 150 NSMiniaturizableWindowMask | |
| 185 NSResizableWindowMask ) | 151 NSResizableWindowMask ) |
| 186 backing:NSBackingStoreBuffered | 152 backing:NSBackingStoreBuffered |
| 187 defer:NO]; | 153 defer:NO]; |
| 188 [window_ setTitle:kWindowTitle]; | 154 [window_ setTitle:kWindowTitle]; |
| 189 NSView* content = [window_ contentView]; | 155 NSView* content = [window_ contentView]; |
| 190 | 156 |
| 191 // If the window is allowed to get too small, it will wreck the view bindings. | 157 // If the window is allowed to get too small, it will wreck the view bindings. |
| 192 NSSize min_size = NSMakeSize(kMinimumWindowWidth, kMinimumWindowHeight); | 158 NSSize min_size = NSMakeSize(kMinimumWindowWidth, kMinimumWindowHeight); |
| 193 min_size = [content convertSize:min_size toView:nil]; | 159 min_size = [content convertSize:min_size toView:nil]; |
| 194 // Note that this takes window coordinates. | 160 // Note that this takes window coordinates. |
| 195 [window_ setContentMinSize:min_size]; | 161 [window_ setContentMinSize:min_size]; |
| 196 | 162 |
| 197 // Rely on the window delegate to clean us up rather than immediately | 163 // Rely on the window delegate to clean us up rather than immediately |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 285 if (event.skip_in_browser) | 251 if (event.skip_in_browser) |
| 286 return; | 252 return; |
| 287 | 253 |
| 288 // The event handling to get this strictly right is a tangle; cheat here a bit | 254 // The event handling to get this strictly right is a tangle; cheat here a bit |
| 289 // by just letting the menus have a chance at it. | 255 // by just letting the menus have a chance at it. |
| 290 if ([event.os_event type] == NSKeyDown) | 256 if ([event.os_event type] == NSKeyDown) |
| 291 [[NSApp mainMenu] performKeyEquivalent:event.os_event]; | 257 [[NSApp mainMenu] performKeyEquivalent:event.os_event]; |
| 292 } | 258 } |
| 293 | 259 |
| 294 } // namespace content | 260 } // namespace content |
| OLD | NEW |