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 #ifndef CHROME_BROWSER_UI_COCOA_EXTENSIONS_SHELL_WINDOW_COCOA_H_ | 5 #ifndef CHROME_BROWSER_UI_COCOA_EXTENSIONS_NATIVE_APP_WINDOW_COCOA_H_ |
6 #define CHROME_BROWSER_UI_COCOA_EXTENSIONS_SHELL_WINDOW_COCOA_H_ | 6 #define CHROME_BROWSER_UI_COCOA_EXTENSIONS_NATIVE_APP_WINDOW_COCOA_H_ |
7 | 7 |
8 #import <Cocoa/Cocoa.h> | 8 #import <Cocoa/Cocoa.h> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/memory/scoped_nsobject.h" | 11 #include "base/memory/scoped_nsobject.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #import "chrome/browser/ui/cocoa/browser_command_executor.h" | 13 #import "chrome/browser/ui/cocoa/browser_command_executor.h" |
14 #include "chrome/browser/ui/cocoa/constrained_window_mac.h" | 14 #include "chrome/browser/ui/cocoa/constrained_window_mac.h" |
15 #include "chrome/browser/ui/extensions/native_shell_window.h" | 15 #include "chrome/browser/ui/extensions/native_app_window.h" |
16 #include "chrome/browser/ui/extensions/shell_window.h" | 16 #include "chrome/browser/ui/extensions/shell_window.h" |
17 #include "chrome/common/extensions/draggable_region.h" | 17 #include "chrome/common/extensions/draggable_region.h" |
18 #import "third_party/GTM/AppKit/GTMWindowSheetController.h" | 18 #import "third_party/GTM/AppKit/GTMWindowSheetController.h" |
19 #include "ui/gfx/rect.h" | 19 #include "ui/gfx/rect.h" |
20 | 20 |
21 class ExtensionKeybindingRegistryCocoa; | 21 class ExtensionKeybindingRegistryCocoa; |
22 class Profile; | 22 class Profile; |
23 class ShellWindowCocoa; | 23 class NativeAppWindowCocoa; |
24 @class ShellNSWindow; | 24 @class ShellNSWindow; |
25 class SkRegion; | 25 class SkRegion; |
26 | 26 |
27 // A window controller for a minimal window to host a web app view. Passes | 27 // A window controller for a minimal window to host a web app view. Passes |
28 // Objective-C notifications to the C++ bridge. | 28 // Objective-C notifications to the C++ bridge. |
29 @interface ShellWindowController : NSWindowController | 29 @interface NativeAppWindowController : NSWindowController |
30 <NSWindowDelegate, | 30 <NSWindowDelegate, |
31 GTMWindowSheetControllerDelegate, | 31 GTMWindowSheetControllerDelegate, |
32 ConstrainedWindowSupport, | 32 ConstrainedWindowSupport, |
33 BrowserCommandExecutor> { | 33 BrowserCommandExecutor> { |
34 @private | 34 @private |
35 ShellWindowCocoa* shellWindow_; // Weak; owns self. | 35 NativeAppWindowCocoa* appWindow_; // Weak; owns self. |
36 // Manages per-window sheets. | 36 // Manages per-window sheets. |
37 scoped_nsobject<GTMWindowSheetController> sheetController_; | 37 scoped_nsobject<GTMWindowSheetController> sheetController_; |
38 } | 38 } |
39 | 39 |
40 @property(assign, nonatomic) ShellWindowCocoa* shellWindow; | 40 @property(assign, nonatomic) NativeAppWindowCocoa* appWindow; |
41 | 41 |
42 // Consults the Command Registry to see if this |event| needs to be handled as | 42 // Consults the Command Registry to see if this |event| needs to be handled as |
43 // an extension command and returns YES if so (NO otherwise). | 43 // an extension command and returns YES if so (NO otherwise). |
44 - (BOOL)handledByExtensionCommand:(NSEvent*)event; | 44 - (BOOL)handledByExtensionCommand:(NSEvent*)event; |
45 | 45 |
46 @end | 46 @end |
47 | 47 |
48 // Cocoa bridge to ShellWindow. | 48 // Cocoa bridge to AppWindow. |
49 class ShellWindowCocoa : public NativeShellWindow { | 49 class NativeAppWindowCocoa : public NativeAppWindow { |
50 public: | 50 public: |
51 ShellWindowCocoa(ShellWindow* shell_window, | 51 NativeAppWindowCocoa(ShellWindow* shell_window, |
52 const ShellWindow::CreateParams& params); | 52 const ShellWindow::CreateParams& params); |
53 | 53 |
54 // BaseWindow implementation. | 54 // BaseWindow implementation. |
55 virtual bool IsActive() const OVERRIDE; | 55 virtual bool IsActive() const OVERRIDE; |
56 virtual bool IsMaximized() const OVERRIDE; | 56 virtual bool IsMaximized() const OVERRIDE; |
57 virtual bool IsMinimized() const OVERRIDE; | 57 virtual bool IsMinimized() const OVERRIDE; |
58 virtual bool IsFullscreen() const OVERRIDE; | 58 virtual bool IsFullscreen() const OVERRIDE; |
59 virtual gfx::NativeWindow GetNativeWindow() OVERRIDE; | 59 virtual gfx::NativeWindow GetNativeWindow() OVERRIDE; |
60 virtual gfx::Rect GetRestoredBounds() const OVERRIDE; | 60 virtual gfx::Rect GetRestoredBounds() const OVERRIDE; |
61 virtual gfx::Rect GetBounds() const OVERRIDE; | 61 virtual gfx::Rect GetBounds() const OVERRIDE; |
62 virtual void Show() OVERRIDE; | 62 virtual void Show() OVERRIDE; |
(...skipping 30 matching lines...) Expand all Loading... |
93 // Called to handle a mouse event. | 93 // Called to handle a mouse event. |
94 void HandleMouseEvent(NSEvent* event); | 94 void HandleMouseEvent(NSEvent* event); |
95 | 95 |
96 // Returns true if |point| in local Cocoa coordinate system falls within | 96 // Returns true if |point| in local Cocoa coordinate system falls within |
97 // the draggable region. | 97 // the draggable region. |
98 bool IsWithinDraggableRegion(NSPoint point) const; | 98 bool IsWithinDraggableRegion(NSPoint point) const; |
99 | 99 |
100 bool use_system_drag() const { return use_system_drag_; } | 100 bool use_system_drag() const { return use_system_drag_; } |
101 | 101 |
102 protected: | 102 protected: |
103 // NativeShellWindow implementation. | 103 // NativeAppWindow implementation. |
104 virtual void SetFullscreen(bool fullscreen) OVERRIDE; | 104 virtual void SetFullscreen(bool fullscreen) OVERRIDE; |
105 virtual bool IsFullscreenOrPending() const OVERRIDE; | 105 virtual bool IsFullscreenOrPending() const OVERRIDE; |
106 virtual void UpdateWindowIcon() OVERRIDE; | 106 virtual void UpdateWindowIcon() OVERRIDE; |
107 virtual void UpdateWindowTitle() OVERRIDE; | 107 virtual void UpdateWindowTitle() OVERRIDE; |
108 virtual void UpdateDraggableRegions( | 108 virtual void UpdateDraggableRegions( |
109 const std::vector<extensions::DraggableRegion>& regions) OVERRIDE; | 109 const std::vector<extensions::DraggableRegion>& regions) OVERRIDE; |
110 virtual void HandleKeyboardEvent( | 110 virtual void HandleKeyboardEvent( |
111 const content::NativeWebKeyboardEvent& event) OVERRIDE; | 111 const content::NativeWebKeyboardEvent& event) OVERRIDE; |
112 virtual void RenderViewHostChanged() OVERRIDE {} | 112 virtual void RenderViewHostChanged() OVERRIDE {} |
113 | 113 |
114 private: | 114 private: |
115 virtual ~ShellWindowCocoa(); | 115 virtual ~NativeAppWindowCocoa(); |
116 | 116 |
117 ShellNSWindow* window() const; | 117 ShellNSWindow* window() const; |
118 | 118 |
119 content::WebContents* web_contents() const { | 119 content::WebContents* web_contents() const { |
120 return shell_window_->web_contents(); | 120 return shell_window_->web_contents(); |
121 } | 121 } |
122 const extensions::Extension* extension() const { | 122 const extensions::Extension* extension() const { |
123 return shell_window_->extension(); | 123 return shell_window_->extension(); |
124 } | 124 } |
125 | 125 |
126 void InstallView(); | 126 void InstallView(); |
127 void UninstallView(); | 127 void UninstallView(); |
128 void InstallDraggableRegionViews(); | 128 void InstallDraggableRegionViews(); |
129 void UpdateDraggableRegionsForSystemDrag( | 129 void UpdateDraggableRegionsForSystemDrag( |
130 const std::vector<extensions::DraggableRegion>& regions, | 130 const std::vector<extensions::DraggableRegion>& regions, |
131 const extensions::DraggableRegion* draggable_area); | 131 const extensions::DraggableRegion* draggable_area); |
132 void UpdateDraggableRegionsForCustomDrag( | 132 void UpdateDraggableRegionsForCustomDrag( |
133 const std::vector<extensions::DraggableRegion>& regions); | 133 const std::vector<extensions::DraggableRegion>& regions); |
134 | 134 |
135 ShellWindow* shell_window_; // weak - ShellWindow owns NativeShellWindow. | 135 ShellWindow* shell_window_; // weak - ShellWindow owns NativeAppWindow. |
136 | 136 |
137 bool has_frame_; | 137 bool has_frame_; |
138 | 138 |
139 bool is_fullscreen_; | 139 bool is_fullscreen_; |
140 NSRect restored_bounds_; | 140 NSRect restored_bounds_; |
141 | 141 |
142 gfx::Size min_size_; | 142 gfx::Size min_size_; |
143 gfx::Size max_size_; | 143 gfx::Size max_size_; |
144 | 144 |
145 scoped_nsobject<ShellWindowController> window_controller_; | 145 scoped_nsobject<NativeAppWindowController> window_controller_; |
146 NSInteger attention_request_id_; // identifier from requestUserAttention | 146 NSInteger attention_request_id_; // identifier from requestUserAttention |
147 | 147 |
148 // Indicates whether system drag or custom drag should be used, depending on | 148 // Indicates whether system drag or custom drag should be used, depending on |
149 // the complexity of draggable regions. | 149 // the complexity of draggable regions. |
150 bool use_system_drag_; | 150 bool use_system_drag_; |
151 | 151 |
152 // For system drag, the whole window is draggable and the non-draggable areas | 152 // For system drag, the whole window is draggable and the non-draggable areas |
153 // have to been explicitly excluded. | 153 // have to been explicitly excluded. |
154 std::vector<gfx::Rect> system_drag_exclude_areas_; | 154 std::vector<gfx::Rect> system_drag_exclude_areas_; |
155 | 155 |
156 // For custom drag, the whole window is non-draggable and the draggable region | 156 // For custom drag, the whole window is non-draggable and the draggable region |
157 // has to been explicitly provided. | 157 // has to been explicitly provided. |
158 scoped_ptr<SkRegion> draggable_region_; // used in custom drag. | 158 scoped_ptr<SkRegion> draggable_region_; // used in custom drag. |
159 | 159 |
160 // Mouse location since the last mouse event, in screen coordinates. This is | 160 // Mouse location since the last mouse event, in screen coordinates. This is |
161 // used in custom drag to compute the window movement. | 161 // used in custom drag to compute the window movement. |
162 NSPoint last_mouse_location_; | 162 NSPoint last_mouse_location_; |
163 | 163 |
164 // The Extension Command Registry used to determine which keyboard events to | 164 // The Extension Command Registry used to determine which keyboard events to |
165 // handle. | 165 // handle. |
166 scoped_ptr<ExtensionKeybindingRegistryCocoa> extension_keybinding_registry_; | 166 scoped_ptr<ExtensionKeybindingRegistryCocoa> extension_keybinding_registry_; |
167 | 167 |
168 DISALLOW_COPY_AND_ASSIGN(ShellWindowCocoa); | 168 DISALLOW_COPY_AND_ASSIGN(NativeAppWindowCocoa); |
169 }; | 169 }; |
170 | 170 |
171 #endif // CHROME_BROWSER_UI_COCOA_EXTENSIONS_SHELL_WINDOW_COCOA_H_ | 171 #endif // CHROME_BROWSER_UI_COCOA_EXTENSIONS_NATIVE_APP_WINDOW_COCOA_H_ |
OLD | NEW |