| 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 "chrome/browser/ui/panels/panel_browser_window_cocoa.h" | 5 #include "chrome/browser/ui/panels/panel_browser_window_cocoa.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "chrome/browser/tabs/tab_strip_model.h" | 8 #include "chrome/browser/tabs/tab_strip_model.h" |
| 9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/browser/ui/browser_list.h" | 10 #include "chrome/browser/ui/browser_list.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 // screen coordinates (with (0,0) in the low-left corner). | 32 // screen coordinates (with (0,0) in the low-left corner). |
| 33 NSRect ConvertCoordinatesToCocoa(const gfx::Rect& bounds) { | 33 NSRect ConvertCoordinatesToCocoa(const gfx::Rect& bounds) { |
| 34 // Flip coordinates based on the primary screen. | 34 // Flip coordinates based on the primary screen. |
| 35 NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; | 35 NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; |
| 36 | 36 |
| 37 return NSMakeRect( | 37 return NSMakeRect( |
| 38 bounds.x(), NSHeight([screen frame]) - bounds.height() - bounds.y(), | 38 bounds.x(), NSHeight([screen frame]) - bounds.height() - bounds.y(), |
| 39 bounds.width(), bounds.height()); | 39 bounds.width(), bounds.height()); |
| 40 } | 40 } |
| 41 | 41 |
| 42 // Converts a point from the platfrom-independent screen coordinates (with the |
| 43 // (0,0) in the top-left corner of the primary screen) to the Cocoa screen |
| 44 // coordinates (with (0,0) in the low-left corner). |
| 45 NSPoint ConvertPointToCocoaCoordinates(const gfx::Point& point) { |
| 46 // Flip coordinates based on the primary screen. |
| 47 NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; |
| 48 |
| 49 return NSMakePoint(point.x(), NSHeight([screen frame]) - point.y()); |
| 50 } |
| 51 |
| 42 } // namespace | 52 } // namespace |
| 43 | 53 |
| 44 // This creates a shim window class, which in turn creates a Cocoa window | 54 // This creates a shim window class, which in turn creates a Cocoa window |
| 45 // controller which in turn creates actual NSWindow by loading a nib. | 55 // controller which in turn creates actual NSWindow by loading a nib. |
| 46 // Overall chain of ownership is: | 56 // Overall chain of ownership is: |
| 47 // PanelWindowControllerCocoa -> PanelBrowserWindowCocoa -> Panel. | 57 // PanelWindowControllerCocoa -> PanelBrowserWindowCocoa -> Panel. |
| 48 NativePanel* Panel::CreateNativePanel(Browser* browser, Panel* panel, | 58 NativePanel* Panel::CreateNativePanel(Browser* browser, Panel* panel, |
| 49 const gfx::Rect& bounds) { | 59 const gfx::Rect& bounds) { |
| 50 return new PanelBrowserWindowCocoa(browser, panel, bounds); | 60 return new PanelBrowserWindowCocoa(browser, panel, bounds); |
| 51 } | 61 } |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 } | 269 } |
| 260 | 270 |
| 261 void PanelBrowserWindowCocoa::EnsurePanelFullyVisible() { | 271 void PanelBrowserWindowCocoa::EnsurePanelFullyVisible() { |
| 262 [controller_ ensureFullyVisible]; | 272 [controller_ ensureFullyVisible]; |
| 263 } | 273 } |
| 264 | 274 |
| 265 void PanelBrowserWindowCocoa::SetPanelAppIconVisibility(bool visible) { | 275 void PanelBrowserWindowCocoa::SetPanelAppIconVisibility(bool visible) { |
| 266 // TODO(dimich): to be implemented. | 276 // TODO(dimich): to be implemented. |
| 267 } | 277 } |
| 268 | 278 |
| 279 void PanelBrowserWindowCocoa::SetPanelAlwaysOnTop(bool on_top) { |
| 280 [controller_ setAlwaysOnTop:on_top]; |
| 281 } |
| 282 |
| 269 void PanelBrowserWindowCocoa::DidCloseNativeWindow() { | 283 void PanelBrowserWindowCocoa::DidCloseNativeWindow() { |
| 270 DCHECK(!isClosed()); | 284 DCHECK(!isClosed()); |
| 271 panel_->OnNativePanelClosed(); | 285 panel_->OnNativePanelClosed(); |
| 272 controller_ = NULL; | 286 controller_ = NULL; |
| 273 } | 287 } |
| 274 | 288 |
| 275 gfx::Size PanelBrowserWindowCocoa::WindowSizeFromContentSize( | 289 gfx::Size PanelBrowserWindowCocoa::WindowSizeFromContentSize( |
| 276 const gfx::Size& content_size) const { | 290 const gfx::Size& content_size) const { |
| 277 NSWindow* window = [controller_ window]; | 291 NSWindow* window = [controller_ window]; |
| 278 NSRect content = NSMakeRect(0, 0, | 292 NSRect content = NSMakeRect(0, 0, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 303 int index) { | 317 int index) { |
| 304 [controller_ tabDetached:contents->web_contents()]; | 318 [controller_ tabDetached:contents->web_contents()]; |
| 305 } | 319 } |
| 306 | 320 |
| 307 // NativePanelTesting implementation. | 321 // NativePanelTesting implementation. |
| 308 class NativePanelTestingCocoa : public NativePanelTesting { | 322 class NativePanelTestingCocoa : public NativePanelTesting { |
| 309 public: | 323 public: |
| 310 NativePanelTestingCocoa(NativePanel* native_panel); | 324 NativePanelTestingCocoa(NativePanel* native_panel); |
| 311 virtual ~NativePanelTestingCocoa() { } | 325 virtual ~NativePanelTestingCocoa() { } |
| 312 // Overridden from NativePanelTesting | 326 // Overridden from NativePanelTesting |
| 313 virtual void PressLeftMouseButtonTitlebar(const gfx::Point& point) OVERRIDE; | 327 virtual void PressLeftMouseButtonTitlebar( |
| 328 const gfx::Point& mouse_location) OVERRIDE; |
| 314 virtual void ReleaseMouseButtonTitlebar() OVERRIDE; | 329 virtual void ReleaseMouseButtonTitlebar() OVERRIDE; |
| 315 virtual void DragTitlebar(int delta_x, int delta_y) OVERRIDE; | 330 virtual void DragTitlebar(const gfx::Point& mouse_location) OVERRIDE; |
| 316 virtual void CancelDragTitlebar() OVERRIDE; | 331 virtual void CancelDragTitlebar() OVERRIDE; |
| 317 virtual void FinishDragTitlebar() OVERRIDE; | 332 virtual void FinishDragTitlebar() OVERRIDE; |
| 318 virtual bool VerifyDrawingAttention() const OVERRIDE; | 333 virtual bool VerifyDrawingAttention() const OVERRIDE; |
| 319 virtual bool VerifyActiveState(bool is_active) OVERRIDE; | 334 virtual bool VerifyActiveState(bool is_active) OVERRIDE; |
| 320 virtual bool IsWindowSizeKnown() const OVERRIDE; | 335 virtual bool IsWindowSizeKnown() const OVERRIDE; |
| 321 virtual bool IsAnimatingBounds() const OVERRIDE; | 336 virtual bool IsAnimatingBounds() const OVERRIDE; |
| 322 | 337 |
| 323 private: | 338 private: |
| 324 PanelTitlebarViewCocoa* titlebar() const; | 339 PanelTitlebarViewCocoa* titlebar() const; |
| 325 // Weak, assumed always to outlive this test API object. | 340 // Weak, assumed always to outlive this test API object. |
| 326 PanelBrowserWindowCocoa* native_panel_window_; | 341 PanelBrowserWindowCocoa* native_panel_window_; |
| 327 }; | 342 }; |
| 328 | 343 |
| 329 // static | 344 // static |
| 330 NativePanelTesting* NativePanelTesting::Create(NativePanel* native_panel) { | 345 NativePanelTesting* NativePanelTesting::Create(NativePanel* native_panel) { |
| 331 return new NativePanelTestingCocoa(native_panel); | 346 return new NativePanelTestingCocoa(native_panel); |
| 332 } | 347 } |
| 333 | 348 |
| 334 NativePanelTestingCocoa::NativePanelTestingCocoa(NativePanel* native_panel) | 349 NativePanelTestingCocoa::NativePanelTestingCocoa(NativePanel* native_panel) |
| 335 : native_panel_window_(static_cast<PanelBrowserWindowCocoa*>(native_panel)) { | 350 : native_panel_window_(static_cast<PanelBrowserWindowCocoa*>(native_panel)) { |
| 336 } | 351 } |
| 337 | 352 |
| 338 PanelTitlebarViewCocoa* NativePanelTestingCocoa::titlebar() const { | 353 PanelTitlebarViewCocoa* NativePanelTestingCocoa::titlebar() const { |
| 339 return [native_panel_window_->controller_ titlebarView]; | 354 return [native_panel_window_->controller_ titlebarView]; |
| 340 } | 355 } |
| 341 | 356 |
| 342 void NativePanelTestingCocoa::PressLeftMouseButtonTitlebar( | 357 void NativePanelTestingCocoa::PressLeftMouseButtonTitlebar( |
| 343 const gfx::Point& point) { | 358 const gfx::Point& mouse_location) { |
| 344 [titlebar() pressLeftMouseButtonTitlebar]; | 359 [titlebar() pressLeftMouseButtonTitlebar:ConvertPointToCocoaCoordinates( |
| 360 mouse_location)]; |
| 345 } | 361 } |
| 346 | 362 |
| 347 void NativePanelTestingCocoa::ReleaseMouseButtonTitlebar() { | 363 void NativePanelTestingCocoa::ReleaseMouseButtonTitlebar() { |
| 348 [titlebar() releaseLeftMouseButtonTitlebar]; | 364 [titlebar() releaseLeftMouseButtonTitlebar]; |
| 349 } | 365 } |
| 350 | 366 |
| 351 void NativePanelTestingCocoa::DragTitlebar(int delta_x, int delta_y) { | 367 void NativePanelTestingCocoa::DragTitlebar(const gfx::Point& mouse_location) { |
| 352 [titlebar() dragTitlebarDeltaX:delta_x deltaY:delta_y]; | 368 [titlebar() dragTitlebar:ConvertPointToCocoaCoordinates(mouse_location)]; |
| 353 } | 369 } |
| 354 | 370 |
| 355 void NativePanelTestingCocoa::CancelDragTitlebar() { | 371 void NativePanelTestingCocoa::CancelDragTitlebar() { |
| 356 [titlebar() cancelDragTitlebar]; | 372 [titlebar() cancelDragTitlebar]; |
| 357 } | 373 } |
| 358 | 374 |
| 359 void NativePanelTestingCocoa::FinishDragTitlebar() { | 375 void NativePanelTestingCocoa::FinishDragTitlebar() { |
| 360 [titlebar() finishDragTitlebar]; | 376 [titlebar() finishDragTitlebar]; |
| 361 } | 377 } |
| 362 | 378 |
| 363 bool NativePanelTestingCocoa::VerifyDrawingAttention() const { | 379 bool NativePanelTestingCocoa::VerifyDrawingAttention() const { |
| 364 return [titlebar() isDrawingAttention]; | 380 return [titlebar() isDrawingAttention]; |
| 365 } | 381 } |
| 366 | 382 |
| 367 bool NativePanelTestingCocoa::VerifyActiveState(bool is_active) { | 383 bool NativePanelTestingCocoa::VerifyActiveState(bool is_active) { |
| 368 // TODO(jianli): to be implemented. | 384 // TODO(jianli): to be implemented. |
| 369 return false; | 385 return false; |
| 370 } | 386 } |
| 371 | 387 |
| 372 bool NativePanelTestingCocoa::IsWindowSizeKnown() const { | 388 bool NativePanelTestingCocoa::IsWindowSizeKnown() const { |
| 373 return true; | 389 return true; |
| 374 } | 390 } |
| 375 | 391 |
| 376 bool NativePanelTestingCocoa::IsAnimatingBounds() const { | 392 bool NativePanelTestingCocoa::IsAnimatingBounds() const { |
| 377 return [native_panel_window_->controller_ isAnimatingBounds]; | 393 return [native_panel_window_->controller_ isAnimatingBounds]; |
| 378 } | 394 } |
| OLD | NEW |