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

Side by Side Diff: chrome/browser/ui/views/extensions/app_base_window_views.cc

Issue 11280173: Rename ShellWindow* classes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix mac build Created 8 years 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/views/extensions/app_base_window_views.h"
6
7 #include "chrome/browser/extensions/extension_host.h"
8 #include "chrome/browser/favicon/favicon_tab_helper.h"
9 #include "chrome/browser/ui/views/extensions/app_window_views.h"
10 #include "chrome/browser/ui/views/extensions/extension_keybinding_registry_views .h"
11 #include "chrome/common/extensions/draggable_region.h"
12 #include "chrome/common/extensions/extension.h"
13 #include "content/public/browser/render_view_host.h"
14 #include "content/public/browser/render_widget_host_view.h"
15 #include "content/public/browser/web_contents.h"
16 #include "content/public/browser/web_contents_view.h"
17 #include "ui/views/controls/webview/webview.h"
18 #include "ui/views/widget/widget.h"
19 #include "ui/views/window/non_client_view.h"
20
21 AppBaseWindowViews::AppBaseWindowViews(
22 ShellWindow* shell_window,
23 const ShellWindow::CreateParams& win_params)
24 : shell_window_(shell_window),
25 web_view_(NULL),
26 window_(NULL),
27 is_fullscreen_(false),
28 frameless_(win_params.frame == ShellWindow::CreateParams::FRAME_NONE) {
29 minimum_size_ = win_params.minimum_size;
30 maximum_size_ = win_params.maximum_size;
31 }
32
33 AppBaseWindowViews::~AppBaseWindowViews() {
34 web_view_->SetWebContents(NULL);
35 }
36
37 void AppBaseWindowViews::Initialize(
38 const ShellWindow::CreateParams& params) {
39 window_ = new views::Widget;
40 InitializeWindow(params.bounds);
41 extension_keybinding_registry_.reset(
42 new ExtensionKeybindingRegistryViews(
43 profile(),
44 window()->GetFocusManager(),
45 extensions::ExtensionKeybindingRegistry::PLATFORM_APPS_ONLY,
46 shell_window()));
47 OnViewWasResized();
48 }
49
50 // BaseWindow implementation.
51
52 bool AppBaseWindowViews::IsActive() const {
53 return window_->IsActive();
54 }
55
56 bool AppBaseWindowViews::IsMaximized() const {
57 return window_->IsMaximized();
58 }
59
60 bool AppBaseWindowViews::IsMinimized() const {
61 return window_->IsMinimized();
62 }
63
64 bool AppBaseWindowViews::IsFullscreen() const {
65 return window_->IsFullscreen();
66 }
67
68 gfx::NativeWindow AppBaseWindowViews::GetNativeWindow() {
69 return window_->GetNativeWindow();
70 }
71
72 gfx::Rect AppBaseWindowViews::GetRestoredBounds() const {
73 return window_->GetRestoredBounds();
74 }
75
76 gfx::Rect AppBaseWindowViews::GetBounds() const {
77 return window_->GetWindowBoundsInScreen();
78 }
79
80 void AppBaseWindowViews::Show() {
81 if (window_->IsVisible()) {
82 window_->Activate();
83 return;
84 }
85
86 window_->Show();
87 }
88
89 void AppBaseWindowViews::ShowInactive() {
90 if (window_->IsVisible())
91 return;
92 window_->ShowInactive();
93 }
94
95 void AppBaseWindowViews::Hide() {
96 window_->Hide();
97 }
98
99 void AppBaseWindowViews::Close() {
100 window_->Close();
101 }
102
103 void AppBaseWindowViews::Activate() {
104 window_->Activate();
105 }
106
107 void AppBaseWindowViews::Deactivate() {
108 window_->Deactivate();
109 }
110
111 void AppBaseWindowViews::Maximize() {
112 window_->Maximize();
113 }
114
115 void AppBaseWindowViews::Minimize() {
116 window_->Minimize();
117 }
118
119 void AppBaseWindowViews::Restore() {
120 window_->Restore();
121 }
122
123 void AppBaseWindowViews::SetBounds(const gfx::Rect& bounds) {
124 GetWidget()->SetBounds(bounds);
125 }
126
127 void AppBaseWindowViews::FlashFrame(bool flash) {
128 window_->FlashFrame(flash);
129 }
130
131 bool AppBaseWindowViews::IsAlwaysOnTop() const {
132 return false;
133 }
134
135 // WidgetDelegate implementation.
136
137 views::View* AppBaseWindowViews::GetContentsView() {
138 return this;
139 }
140
141 bool AppBaseWindowViews::CanResize() const {
142 return maximum_size_.IsEmpty() || minimum_size_ != maximum_size_;
143 }
144
145 bool AppBaseWindowViews::CanMaximize() const {
146 return CanResize();
147 }
148
149 views::Widget* AppBaseWindowViews::GetWidget() {
150 return window_;
151 }
152
153 const views::Widget* AppBaseWindowViews::GetWidget() const {
154 return window_;
155 }
156
157 string16 AppBaseWindowViews::GetWindowTitle() const {
158 return shell_window_->GetTitle();
159 }
160
161 void AppBaseWindowViews::DeleteDelegate() {
162 shell_window_->OnNativeClose();
163 }
164
165 views::View* AppBaseWindowViews::GetInitiallyFocusedView() {
166 return web_view_;
167 }
168
169 bool AppBaseWindowViews::ShouldDescendIntoChildForEventHandling(
170 gfx::NativeView child,
171 const gfx::Point& location) {
172 #if defined(USE_AURA)
173 DCHECK_EQ(child, web_view_->web_contents()->GetView()->GetNativeView());
174 // Shell window should claim mouse events that fall within the draggable
175 // region.
176 return !draggable_region_.get() ||
177 !draggable_region_->contains(location.x(), location.y());
178 #else
179 return true;
180 #endif
181 }
182
183 gfx::ImageSkia AppBaseWindowViews::GetWindowAppIcon() {
184 gfx::Image app_icon = shell_window_->app_icon();
185 if (app_icon.IsEmpty())
186 return GetWindowIcon();
187 else
188 return *app_icon.ToImageSkia();
189 }
190
191 gfx::ImageSkia AppBaseWindowViews::GetWindowIcon() {
192 content::WebContents* web_contents = shell_window_->web_contents();
193 if (web_contents) {
194 FaviconTabHelper* favicon_tab_helper =
195 FaviconTabHelper::FromWebContents(web_contents);
196 gfx::Image app_icon = favicon_tab_helper->GetFavicon();
197 if (!app_icon.IsEmpty())
198 return *app_icon.ToImageSkia();
199 }
200 return gfx::ImageSkia();
201 }
202
203 bool AppBaseWindowViews::ShouldShowWindowTitle() const {
204 return false;
205 }
206
207 void AppBaseWindowViews::OnWidgetMove() {
208 shell_window_->SaveWindowPosition();
209 }
210
211 // Protected methods.
212
213 void AppBaseWindowViews::OnViewWasResized() {
214 }
215
216 // views::View implementation.
217
218 void AppBaseWindowViews::Layout() {
219 DCHECK(web_view_);
220 web_view_->SetBounds(0, 0, width(), height());
221 OnViewWasResized();
222 }
223
224 void AppBaseWindowViews::ViewHierarchyChanged(
225 bool is_add, views::View *parent, views::View *child) {
226 if (is_add && child == this) {
227 web_view_ = new views::WebView(NULL);
228 AddChildView(web_view_);
229 web_view_->SetWebContents(web_contents());
230 }
231 }
232
233 gfx::Size AppBaseWindowViews::GetMinimumSize() {
234 return minimum_size_;
235 }
236
237 gfx::Size AppBaseWindowViews::GetMaximumSize() {
238 return maximum_size_;
239 }
240
241 void AppBaseWindowViews::OnFocus() {
242 web_view_->RequestFocus();
243 }
244
245 void AppBaseWindowViews::SaveWindowPlacement(
246 const gfx::Rect& bounds,
247 ui::WindowShowState show_state) {
248 views::WidgetDelegate::SaveWindowPlacement(bounds, show_state);
249 shell_window_->SaveWindowPosition();
250 }
251
252 // AppBaseWindow implementation.
253
254 void AppBaseWindowViews::SetFullscreen(bool fullscreen) {
255 is_fullscreen_ = fullscreen;
256 window_->SetFullscreen(fullscreen);
257 // TODO(jeremya) we need to call RenderViewHost::ExitFullscreen() if we
258 // ever drop the window out of fullscreen in response to something that
259 // wasn't the app calling webkitCancelFullScreen().
260 }
261
262 bool AppBaseWindowViews::IsFullscreenOrPending() const {
263 return is_fullscreen_;
264 }
265
266 void AppBaseWindowViews::UpdateWindowIcon() {
267 window_->UpdateWindowIcon();
268 }
269
270 void AppBaseWindowViews::UpdateWindowTitle() {
271 window_->UpdateWindowTitle();
272 }
273
274 void AppBaseWindowViews::UpdateDraggableRegions(
275 const std::vector<extensions::DraggableRegion>& regions) {
276 // Draggable region is not supported for non-frameless window.
277 if (!frameless_)
278 return;
279
280 draggable_region_.reset(ShellWindow::RawDraggableRegionsToSkRegion(regions));
281 OnViewWasResized();
282 }
283
284 void AppBaseWindowViews::HandleKeyboardEvent(
285 const content::NativeWebKeyboardEvent& event) {
286 unhandled_keyboard_event_handler_.HandleKeyboardEvent(event,
287 GetFocusManager());
288 }
289
290 void AppBaseWindowViews::RenderViewHostChanged() {
291 OnViewWasResized();
292 }
293
294 //------------------------------------------------------------------------------
295
296 // static
297 AppBaseWindow* AppBaseWindow::Create(
298 ShellWindow* shell_window, const ShellWindow::CreateParams& params) {
299 AppBaseWindowViews* window = new AppWindowViews(shell_window, params);
300 window->Initialize(params);
301 return window;
302 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698