| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/ui/cocoa/apps/native_app_window_cocoa.h" | 5 #include "chrome/browser/ui/cocoa/apps/native_app_window_cocoa.h" |
| 6 | 6 |
| 7 #include "apps/app_shim/extension_app_shim_handler_mac.h" | 7 #include "apps/app_shim/extension_app_shim_handler_mac.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/mac/mac_util.h" | 9 #include "base/mac/mac_util.h" |
| 10 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/ui/cocoa/browser_window_utils.h" | 12 #include "chrome/browser/ui/cocoa/browser_window_utils.h" |
| 13 #import "chrome/browser/ui/cocoa/chrome_event_processing_window.h" | 13 #import "chrome/browser/ui/cocoa/chrome_event_processing_window.h" |
| 14 #include "chrome/browser/ui/cocoa/extensions/extension_keybinding_registry_cocoa
.h" | 14 #include "chrome/browser/ui/cocoa/extensions/extension_keybinding_registry_cocoa
.h" |
| 15 #include "chrome/browser/ui/cocoa/extensions/extension_view_mac.h" | 15 #include "chrome/browser/ui/cocoa/extensions/extension_view_mac.h" |
| 16 #include "chrome/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
| 17 #include "chrome/common/extensions/extension.h" | 17 #include "chrome/common/extensions/extension.h" |
| 18 #include "content/public/browser/native_web_keyboard_event.h" | 18 #include "content/public/browser/native_web_keyboard_event.h" |
| 19 #include "content/public/browser/notification_source.h" | |
| 20 #include "content/public/browser/notification_types.h" | |
| 21 #include "content/public/browser/render_widget_host_view.h" | 19 #include "content/public/browser/render_widget_host_view.h" |
| 22 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
| 23 #include "content/public/browser/web_contents_view.h" | 21 #include "content/public/browser/web_contents_view.h" |
| 24 #include "third_party/skia/include/core/SkRegion.h" | 22 #include "third_party/skia/include/core/SkRegion.h" |
| 25 | 23 |
| 26 // NOTE: State Before Update. | 24 // NOTE: State Before Update. |
| 27 // | 25 // |
| 28 // Internal state, such as |is_maximized_|, must be set before the window | 26 // Internal state, such as |is_maximized_|, must be set before the window |
| 29 // state is changed so that it is accurate when e.g. a resize results in a call | 27 // state is changed so that it is accurate when e.g. a resize results in a call |
| 30 // to |OnNativeWindowChanged|. | 28 // to |OnNativeWindowChanged|. |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 ShellWindow* shell_window, | 248 ShellWindow* shell_window, |
| 251 const ShellWindow::CreateParams& params) | 249 const ShellWindow::CreateParams& params) |
| 252 : shell_window_(shell_window), | 250 : shell_window_(shell_window), |
| 253 has_frame_(params.frame == ShellWindow::FRAME_CHROME), | 251 has_frame_(params.frame == ShellWindow::FRAME_CHROME), |
| 254 is_hidden_(false), | 252 is_hidden_(false), |
| 255 is_hidden_with_app_(false), | 253 is_hidden_with_app_(false), |
| 256 is_maximized_(false), | 254 is_maximized_(false), |
| 257 is_fullscreen_(false), | 255 is_fullscreen_(false), |
| 258 attention_request_id_(0), | 256 attention_request_id_(0), |
| 259 use_system_drag_(true) { | 257 use_system_drag_(true) { |
| 258 Observe(web_contents()); |
| 259 |
| 260 // Flip coordinates based on the primary screen. | 260 // Flip coordinates based on the primary screen. |
| 261 NSRect main_screen_rect = [[[NSScreen screens] objectAtIndex:0] frame]; | 261 NSRect main_screen_rect = [[[NSScreen screens] objectAtIndex:0] frame]; |
| 262 NSRect cocoa_bounds = NSMakeRect(params.bounds.x(), | 262 NSRect cocoa_bounds = NSMakeRect(params.bounds.x(), |
| 263 NSHeight(main_screen_rect) - params.bounds.y() - params.bounds.height(), | 263 NSHeight(main_screen_rect) - params.bounds.y() - params.bounds.height(), |
| 264 params.bounds.width(), params.bounds.height()); | 264 params.bounds.width(), params.bounds.height()); |
| 265 | 265 |
| 266 // If coordinates are < 0, center window on primary screen | 266 // If coordinates are < 0, center window on primary screen. |
| 267 if (params.bounds.x() == INT_MIN) { | 267 if (params.bounds.x() == INT_MIN) { |
| 268 cocoa_bounds.origin.x = | 268 cocoa_bounds.origin.x = |
| 269 floor((NSWidth(main_screen_rect) - NSWidth(cocoa_bounds)) / 2); | 269 floor((NSWidth(main_screen_rect) - NSWidth(cocoa_bounds)) / 2); |
| 270 } | 270 } |
| 271 if (params.bounds.y() == INT_MIN) { | 271 if (params.bounds.y() == INT_MIN) { |
| 272 cocoa_bounds.origin.y = | 272 cocoa_bounds.origin.y = |
| 273 floor((NSHeight(main_screen_rect) - NSHeight(cocoa_bounds)) / 2); | 273 floor((NSHeight(main_screen_rect) - NSHeight(cocoa_bounds)) / 2); |
| 274 } | 274 } |
| 275 | 275 |
| 276 // Initialize |restored_bounds_| after |cocoa_bounds| have been sanitized. | 276 // Initialize |restored_bounds_| after |cocoa_bounds| have been sanitized. |
| (...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 775 } else { | 775 } else { |
| 776 [NSApp cancelUserAttentionRequest:attention_request_id_]; | 776 [NSApp cancelUserAttentionRequest:attention_request_id_]; |
| 777 attention_request_id_ = 0; | 777 attention_request_id_ = 0; |
| 778 } | 778 } |
| 779 } | 779 } |
| 780 | 780 |
| 781 bool NativeAppWindowCocoa::IsAlwaysOnTop() const { | 781 bool NativeAppWindowCocoa::IsAlwaysOnTop() const { |
| 782 return false; | 782 return false; |
| 783 } | 783 } |
| 784 | 784 |
| 785 void NativeAppWindowCocoa::RenderViewHostChanged() { | 785 void NativeAppWindowCocoa::RenderViewHostChanged( |
| 786 content::RenderViewHost* old_host, |
| 787 content::RenderViewHost* new_host) { |
| 786 web_contents()->GetView()->Focus(); | 788 web_contents()->GetView()->Focus(); |
| 787 } | 789 } |
| 788 | 790 |
| 789 gfx::Insets NativeAppWindowCocoa::GetFrameInsets() const { | 791 gfx::Insets NativeAppWindowCocoa::GetFrameInsets() const { |
| 790 if (!has_frame_) | 792 if (!has_frame_) |
| 791 return gfx::Insets(); | 793 return gfx::Insets(); |
| 792 | 794 |
| 793 // Flip the coordinates based on the main screen. | 795 // Flip the coordinates based on the main screen. |
| 794 NSInteger screen_height = | 796 NSInteger screen_height = |
| 795 NSHeight([[[NSScreen screens] objectAtIndex:0] frame]); | 797 NSHeight([[[NSScreen screens] objectAtIndex:0] frame]); |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 953 ShellNSWindow* NativeAppWindowCocoa::window() const { | 955 ShellNSWindow* NativeAppWindowCocoa::window() const { |
| 954 NSWindow* window = [window_controller_ window]; | 956 NSWindow* window = [window_controller_ window]; |
| 955 CHECK(!window || [window isKindOfClass:[ShellNSWindow class]]); | 957 CHECK(!window || [window isKindOfClass:[ShellNSWindow class]]); |
| 956 return static_cast<ShellNSWindow*>(window); | 958 return static_cast<ShellNSWindow*>(window); |
| 957 } | 959 } |
| 958 | 960 |
| 959 void NativeAppWindowCocoa::UpdateRestoredBounds() { | 961 void NativeAppWindowCocoa::UpdateRestoredBounds() { |
| 960 if (IsRestored(*this)) | 962 if (IsRestored(*this)) |
| 961 restored_bounds_ = [window() frame]; | 963 restored_bounds_ = [window() frame]; |
| 962 } | 964 } |
| OLD | NEW |