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

Side by Side Diff: chrome/browser/ui/panels/panel_browser_window_cocoa.mm

Issue 9616037: Change panel drag related methods to use mouse location in screen coordinates. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Patch to reland Created 8 years, 9 months 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
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"
11 #include "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h" 11 #include "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h"
12 #import "chrome/browser/ui/cocoa/browser_window_utils.h" 12 #import "chrome/browser/ui/cocoa/browser_window_utils.h"
13 #include "chrome/browser/ui/panels/panel.h" 13 #include "chrome/browser/ui/panels/panel.h"
14 #include "chrome/browser/ui/panels/panel_manager.h" 14 #include "chrome/browser/ui/panels/panel_manager.h"
15 #import "chrome/browser/ui/panels/panel_titlebar_view_cocoa.h" 15 #import "chrome/browser/ui/panels/panel_titlebar_view_cocoa.h"
16 #import "chrome/browser/ui/panels/panel_utils_cocoa.h"
16 #import "chrome/browser/ui/panels/panel_window_controller_cocoa.h" 17 #import "chrome/browser/ui/panels/panel_window_controller_cocoa.h"
17 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 18 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
18 #include "content/public/browser/native_web_keyboard_event.h" 19 #include "content/public/browser/native_web_keyboard_event.h"
19 20
20 using content::WebContents; 21 using content::WebContents;
21 22
22 namespace { 23 namespace {
23 24
24 // Use this instead of 0 for minimum size of a window when doing opening and 25 // Use this instead of 0 for minimum size of a window when doing opening and
25 // closing animations, since OSX window manager does not like 0-sized windows 26 // closing animations, since OSX window manager does not like 0-sized windows
26 // (according to avi@). 27 // (according to avi@).
27 const int kMinimumWindowSize = 1; 28 const int kMinimumWindowSize = 1;
28 29
29 // TODO(dcheng): Move elsewhere so BrowserWindowCocoa can use them too.
30 // Converts global screen coordinates in platfrom-independent coordinates
31 // (with the (0,0) in the top-left corner of the primary screen) to the Cocoa
32 // screen coordinates (with (0,0) in the low-left corner).
33 NSRect ConvertCoordinatesToCocoa(const gfx::Rect& bounds) {
34 // Flip coordinates based on the primary screen.
35 NSScreen* screen = [[NSScreen screens] objectAtIndex:0];
36
37 return NSMakeRect(
38 bounds.x(), NSHeight([screen frame]) - bounds.height() - bounds.y(),
39 bounds.width(), bounds.height());
40 }
41
42 } // namespace 30 } // namespace
43 31
44 // This creates a shim window class, which in turn creates a Cocoa window 32 // 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. 33 // controller which in turn creates actual NSWindow by loading a nib.
46 // Overall chain of ownership is: 34 // Overall chain of ownership is:
47 // PanelWindowControllerCocoa -> PanelBrowserWindowCocoa -> Panel. 35 // PanelWindowControllerCocoa -> PanelBrowserWindowCocoa -> Panel.
48 NativePanel* Panel::CreateNativePanel(Browser* browser, Panel* panel, 36 NativePanel* Panel::CreateNativePanel(Browser* browser, Panel* panel,
49 const gfx::Rect& bounds) { 37 const gfx::Rect& bounds) {
50 return new PanelBrowserWindowCocoa(browser, panel, bounds); 38 return new PanelBrowserWindowCocoa(browser, panel, bounds);
51 } 39 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 // Browser calls this several times, meaning 'ensure it's shown'. 78 // Browser calls this several times, meaning 'ensure it's shown'.
91 // Animations don't look good when repeated - hence this flag is needed. 79 // Animations don't look good when repeated - hence this flag is needed.
92 if (is_shown_) { 80 if (is_shown_) {
93 return; 81 return;
94 } 82 }
95 // A call to SetPanelBounds() before showing it is required to set 83 // A call to SetPanelBounds() before showing it is required to set
96 // the panel frame properly. 84 // the panel frame properly.
97 SetPanelBoundsInstantly(bounds_); 85 SetPanelBoundsInstantly(bounds_);
98 is_shown_ = true; 86 is_shown_ = true;
99 87
100 NSRect finalFrame = ConvertCoordinatesToCocoa(bounds_); 88 NSRect finalFrame = cocoa_utils::ConvertRectToCocoaCoordinates(bounds_);
101 [controller_ revealAnimatedWithFrame:finalFrame]; 89 [controller_ revealAnimatedWithFrame:finalFrame];
102 } 90 }
103 91
104 gfx::Rect PanelBrowserWindowCocoa::GetPanelBounds() const { 92 gfx::Rect PanelBrowserWindowCocoa::GetPanelBounds() const {
105 return bounds_; 93 return bounds_;
106 } 94 }
107 95
108 // |bounds| is the platform-independent screen coordinates, with (0,0) at 96 // |bounds| is the platform-independent screen coordinates, with (0,0) at
109 // top-left of the primary screen. 97 // top-left of the primary screen.
110 void PanelBrowserWindowCocoa::SetPanelBounds(const gfx::Rect& bounds) { 98 void PanelBrowserWindowCocoa::SetPanelBounds(const gfx::Rect& bounds) {
111 setBoundsInternal(bounds, true); 99 setBoundsInternal(bounds, true);
112 } 100 }
113 101
114 void PanelBrowserWindowCocoa::SetPanelBoundsInstantly(const gfx::Rect& bounds) { 102 void PanelBrowserWindowCocoa::SetPanelBoundsInstantly(const gfx::Rect& bounds) {
115 setBoundsInternal(bounds, false); 103 setBoundsInternal(bounds, false);
116 } 104 }
117 105
118 void PanelBrowserWindowCocoa::setBoundsInternal(const gfx::Rect& bounds, 106 void PanelBrowserWindowCocoa::setBoundsInternal(const gfx::Rect& bounds,
119 bool animate) { 107 bool animate) {
120 // We will call SetPanelBoundsInstantly() once before showing the panel 108 // We will call SetPanelBoundsInstantly() once before showing the panel
121 // and it should set the panel frame correctly. 109 // and it should set the panel frame correctly.
122 if (bounds_ == bounds && is_shown_) 110 if (bounds_ == bounds && is_shown_)
123 return; 111 return;
124 112
125 bounds_ = bounds; 113 bounds_ = bounds;
126 114
127 NSRect frame = ConvertCoordinatesToCocoa(bounds); 115 NSRect frame = cocoa_utils::ConvertRectToCocoaCoordinates(bounds);
128 [controller_ setPanelFrame:frame animate:animate]; 116 [controller_ setPanelFrame:frame animate:animate];
129 } 117 }
130 118
131 void PanelBrowserWindowCocoa::ClosePanel() { 119 void PanelBrowserWindowCocoa::ClosePanel() {
132 if (isClosed()) 120 if (isClosed())
133 return; 121 return;
134 122
135 NSWindow* window = [controller_ window]; 123 NSWindow* window = [controller_ window];
136 [window performClose:controller_]; 124 [window performClose:controller_];
137 } 125 }
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 int index) { 296 int index) {
309 [controller_ tabDetached:contents->web_contents()]; 297 [controller_ tabDetached:contents->web_contents()];
310 } 298 }
311 299
312 // NativePanelTesting implementation. 300 // NativePanelTesting implementation.
313 class NativePanelTestingCocoa : public NativePanelTesting { 301 class NativePanelTestingCocoa : public NativePanelTesting {
314 public: 302 public:
315 NativePanelTestingCocoa(NativePanel* native_panel); 303 NativePanelTestingCocoa(NativePanel* native_panel);
316 virtual ~NativePanelTestingCocoa() { } 304 virtual ~NativePanelTestingCocoa() { }
317 // Overridden from NativePanelTesting 305 // Overridden from NativePanelTesting
318 virtual void PressLeftMouseButtonTitlebar(const gfx::Point& point) OVERRIDE; 306 virtual void PressLeftMouseButtonTitlebar(
307 const gfx::Point& mouse_location) OVERRIDE;
319 virtual void ReleaseMouseButtonTitlebar() OVERRIDE; 308 virtual void ReleaseMouseButtonTitlebar() OVERRIDE;
320 virtual void DragTitlebar(int delta_x, int delta_y) OVERRIDE; 309 virtual void DragTitlebar(const gfx::Point& mouse_location) OVERRIDE;
321 virtual void CancelDragTitlebar() OVERRIDE; 310 virtual void CancelDragTitlebar() OVERRIDE;
322 virtual void FinishDragTitlebar() OVERRIDE; 311 virtual void FinishDragTitlebar() OVERRIDE;
323 virtual bool VerifyDrawingAttention() const OVERRIDE; 312 virtual bool VerifyDrawingAttention() const OVERRIDE;
324 virtual bool VerifyActiveState(bool is_active) OVERRIDE; 313 virtual bool VerifyActiveState(bool is_active) OVERRIDE;
325 virtual bool IsWindowSizeKnown() const OVERRIDE; 314 virtual bool IsWindowSizeKnown() const OVERRIDE;
326 virtual bool IsAnimatingBounds() const OVERRIDE; 315 virtual bool IsAnimatingBounds() const OVERRIDE;
327 316
328 private: 317 private:
329 PanelTitlebarViewCocoa* titlebar() const; 318 PanelTitlebarViewCocoa* titlebar() const;
330 // Weak, assumed always to outlive this test API object. 319 // Weak, assumed always to outlive this test API object.
331 PanelBrowserWindowCocoa* native_panel_window_; 320 PanelBrowserWindowCocoa* native_panel_window_;
332 }; 321 };
333 322
334 // static 323 // static
335 NativePanelTesting* NativePanelTesting::Create(NativePanel* native_panel) { 324 NativePanelTesting* NativePanelTesting::Create(NativePanel* native_panel) {
336 return new NativePanelTestingCocoa(native_panel); 325 return new NativePanelTestingCocoa(native_panel);
337 } 326 }
338 327
339 NativePanelTestingCocoa::NativePanelTestingCocoa(NativePanel* native_panel) 328 NativePanelTestingCocoa::NativePanelTestingCocoa(NativePanel* native_panel)
340 : native_panel_window_(static_cast<PanelBrowserWindowCocoa*>(native_panel)) { 329 : native_panel_window_(static_cast<PanelBrowserWindowCocoa*>(native_panel)) {
341 } 330 }
342 331
343 PanelTitlebarViewCocoa* NativePanelTestingCocoa::titlebar() const { 332 PanelTitlebarViewCocoa* NativePanelTestingCocoa::titlebar() const {
344 return [native_panel_window_->controller_ titlebarView]; 333 return [native_panel_window_->controller_ titlebarView];
345 } 334 }
346 335
347 void NativePanelTestingCocoa::PressLeftMouseButtonTitlebar( 336 void NativePanelTestingCocoa::PressLeftMouseButtonTitlebar(
348 const gfx::Point& point) { 337 const gfx::Point& mouse_location) {
349 [titlebar() pressLeftMouseButtonTitlebar]; 338 // Convert from platform-indepedent screen coordinates to Cocoa's screen
339 // coordinates because PanelTitlebarViewCocoa method takes Cocoa's screen
340 // coordinates.
341 [titlebar() pressLeftMouseButtonTitlebar:
342 cocoa_utils::ConvertPointToCocoaCoordinates(mouse_location)];
350 } 343 }
351 344
352 void NativePanelTestingCocoa::ReleaseMouseButtonTitlebar() { 345 void NativePanelTestingCocoa::ReleaseMouseButtonTitlebar() {
353 [titlebar() releaseLeftMouseButtonTitlebar]; 346 [titlebar() releaseLeftMouseButtonTitlebar];
354 } 347 }
355 348
356 void NativePanelTestingCocoa::DragTitlebar(int delta_x, int delta_y) { 349 void NativePanelTestingCocoa::DragTitlebar(const gfx::Point& mouse_location) {
357 [titlebar() dragTitlebarDeltaX:delta_x deltaY:delta_y]; 350 // Convert from platform-indepedent screen coordinates to Cocoa's screen
351 // coordinates because PanelTitlebarViewCocoa method takes Cocoa's screen
352 // coordinates.
353 [titlebar() dragTitlebar:
354 cocoa_utils::ConvertPointToCocoaCoordinates(mouse_location)];
358 } 355 }
359 356
360 void NativePanelTestingCocoa::CancelDragTitlebar() { 357 void NativePanelTestingCocoa::CancelDragTitlebar() {
361 [titlebar() cancelDragTitlebar]; 358 [titlebar() cancelDragTitlebar];
362 } 359 }
363 360
364 void NativePanelTestingCocoa::FinishDragTitlebar() { 361 void NativePanelTestingCocoa::FinishDragTitlebar() {
365 [titlebar() finishDragTitlebar]; 362 [titlebar() finishDragTitlebar];
366 } 363 }
367 364
368 bool NativePanelTestingCocoa::VerifyDrawingAttention() const { 365 bool NativePanelTestingCocoa::VerifyDrawingAttention() const {
369 return [titlebar() isDrawingAttention]; 366 return [titlebar() isDrawingAttention];
370 } 367 }
371 368
372 bool NativePanelTestingCocoa::VerifyActiveState(bool is_active) { 369 bool NativePanelTestingCocoa::VerifyActiveState(bool is_active) {
373 // TODO(jianli): to be implemented. 370 // TODO(jianli): to be implemented.
374 return false; 371 return false;
375 } 372 }
376 373
377 bool NativePanelTestingCocoa::IsWindowSizeKnown() const { 374 bool NativePanelTestingCocoa::IsWindowSizeKnown() const {
378 return true; 375 return true;
379 } 376 }
380 377
381 bool NativePanelTestingCocoa::IsAnimatingBounds() const { 378 bool NativePanelTestingCocoa::IsAnimatingBounds() const {
382 return [native_panel_window_->controller_ isAnimatingBounds]; 379 return [native_panel_window_->controller_ isAnimatingBounds];
383 } 380 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/panels/panel_browser_view.cc ('k') | chrome/browser/ui/panels/panel_browser_window_gtk.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698