forked from nwjs/nw.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnative_window_mac.h
More file actions
143 lines (117 loc) · 5.48 KB
/
native_window_mac.h
File metadata and controls
143 lines (117 loc) · 5.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// Copyright (c) 2012 Intel Corp
// Copyright (c) 2012 The Chromium Authors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell co
// pies of the Software, and to permit persons to whom the Software is furnished
// to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in al
// l copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IM
// PLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNES
// S FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
// OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WH
// ETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#ifndef CONTENT_NW_SRC_BROWSER_NATIVE_WINDOW_MAC_H_
#define CONTENT_NW_SRC_BROWSER_NATIVE_WINDOW_MAC_H_
#import <Cocoa/Cocoa.h>
#include "base/mac/scoped_nsobject.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "content/nw/src/browser/native_window.h"
@class ShellNSWindow;
@class ShellToolbarDelegate;
class SkRegion;
namespace nw {
class NativeWindowCocoa : public NativeWindow {
public:
explicit NativeWindowCocoa(const base::WeakPtr<content::Shell>& shell,
base::DictionaryValue* manifest);
virtual ~NativeWindowCocoa();
// NativeWindow implementation.
virtual void Close() OVERRIDE;
virtual void Move(const gfx::Rect& pos) OVERRIDE;
virtual void Focus(bool focus) OVERRIDE;
virtual void Show() OVERRIDE;
virtual void Hide() OVERRIDE;
virtual void Maximize() OVERRIDE;
virtual void Unmaximize() OVERRIDE;
virtual void Minimize() OVERRIDE;
virtual void Restore() OVERRIDE;
virtual void SetFullscreen(bool fullscreen) OVERRIDE;
virtual bool IsFullscreen() OVERRIDE;
virtual void SetSize(const gfx::Size& size) OVERRIDE;
virtual gfx::Size GetSize() OVERRIDE;
virtual void SetMinimumSize(int width, int height) OVERRIDE;
virtual void SetMaximumSize(int width, int height) OVERRIDE;
virtual void SetResizable(bool resizable) OVERRIDE;
virtual void SetAlwaysOnTop(bool top) OVERRIDE;
virtual void SetShowInTaskbar(bool show = true) OVERRIDE;
virtual void SetPosition(const std::string& position) OVERRIDE;
virtual void SetPosition(const gfx::Point& position) OVERRIDE;
virtual gfx::Point GetPosition() OVERRIDE;
virtual void SetTitle(const std::string& title) OVERRIDE;
virtual void FlashFrame(bool flash) OVERRIDE;
virtual void SetBadgeLabel(const std::string& badge) OVERRIDE;
virtual void SetKiosk(bool kiosk) OVERRIDE;
virtual bool IsKiosk() OVERRIDE;
virtual void SetMenu(nwapi::Menu* menu) OVERRIDE;
virtual void SetToolbarButtonEnabled(TOOLBAR_BUTTON button,
bool enabled) OVERRIDE;
virtual void SetToolbarUrlEntry(const std::string& url) OVERRIDE;
virtual void SetToolbarIsLoading(bool loading) OVERRIDE;
virtual void SetInitialFocus(bool accept_focus) OVERRIDE;
virtual bool InitialFocus() OVERRIDE;
// Called to handle a mouse event.
void HandleMouseEvent(NSEvent* event);
bool use_system_drag() const { return use_system_drag_; }
SkRegion* draggable_region() const { return draggable_region_.get(); }
void set_is_fullscreen(bool fullscreen) { is_fullscreen_ = fullscreen; }
NSWindow* window() const { return window_; }
protected:
// NativeWindow implementation.
virtual void AddToolbar() OVERRIDE;
virtual void UpdateDraggableRegions(
const std::vector<extensions::DraggableRegion>& regions) OVERRIDE;
virtual void HandleKeyboardEvent(
const content::NativeWebKeyboardEvent& event) OVERRIDE;
void SetNonLionFullscreen(bool fullscreen);
private:
void InstallView();
void UninstallView();
void InstallDraggableRegionViews();
void UpdateDraggableRegionsForSystemDrag(
const std::vector<extensions::DraggableRegion>& regions,
const extensions::DraggableRegion* draggable_area);
void UpdateDraggableRegionsForCustomDrag(
const std::vector<extensions::DraggableRegion>& regions);
NSWindow* window_;
// Delegate to the toolbar.
base::scoped_nsobject<ShellToolbarDelegate> toolbar_delegate_;
bool is_fullscreen_;
bool is_kiosk_;
NSRect restored_bounds_;
NSInteger attention_request_id_; // identifier from requestUserAttention
// Indicates whether system drag or custom drag should be used, depending on
// the complexity of draggable regions.
bool use_system_drag_;
// For system drag, the whole window is draggable and the non-draggable areas
// have to been explicitly excluded.
std::vector<gfx::Rect> system_drag_exclude_areas_;
// For custom drag, the whole window is non-draggable and the draggable region
// has to been explicitly provided.
scoped_ptr<SkRegion> draggable_region_; // used in custom drag.
// Mouse location since the last mouse event, in screen coordinates. This is
// used in custom drag to compute the window movement.
NSPoint last_mouse_location_;
bool initial_focus_;
bool first_show_;
DISALLOW_COPY_AND_ASSIGN(NativeWindowCocoa);
};
} // namespace nw
#endif // CONTENT_NW_SRC_BROWSER_NATIVE_WINDOW_MAC_H_