diff options
author | tapted@chromium.org <tapted@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-26 14:37:23 +0000 |
---|---|---|
committer | tapted@chromium.org <tapted@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-26 14:37:23 +0000 |
commit | fc26960ab9ddb5edbfc196e941f0fe942c8b011d (patch) | |
tree | 807fb063c76408c224ad4cbae8d47c9066a22d67 /ui/gfx/mac | |
parent | ae7ef14ba2d9b5ef0d2c1c092ec98a417e44740d (diff) | |
download | chromium_src-fc26960ab9ddb5edbfc196e941f0fe942c8b011d.zip chromium_src-fc26960ab9ddb5edbfc196e941f0fe942c8b011d.tar.gz chromium_src-fc26960ab9ddb5edbfc196e941f0fe942c8b011d.tar.bz2 |
MacViews: Implement Set/Get*Bounds for NativeWidgetMac.
In toolkit-views, "Bounds" corresponds to the NSWindow frame (including
titlebar and borders). This CL maps that onto NSWindow in
InitNativeWidget, GetWindowBoundsInScreen, GetClientAreaBoundsInScreen,
SetBounds and SetSize, performing the required coordinate system
conversions.
5 more views_unittests pass after this:
BubbleDelegateTest.NonClientHitTest
CustomFrameViewTest.{CannotMaximizeHidesButton, DefaultButtonLayout,
LeadingButtonLayout}, ViewTest.ConversionsToFromScreen.
The CL also adds a cross-platform WidgetTest.GetWindowBoundsInScreen to
ensure the behavior is consistent across platforms, and because there
wasn't really anything to cover just bounds setting (e.g. to verify the
coordinate flipping Cocoa needs to do).
BUG=378134
TEST=views_unittests
Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=279975
Review URL: https://codereview.chromium.org/353643002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@280005 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/gfx/mac')
-rw-r--r-- | ui/gfx/mac/coordinate_conversion.h | 26 | ||||
-rw-r--r-- | ui/gfx/mac/coordinate_conversion.mm | 37 |
2 files changed, 63 insertions, 0 deletions
diff --git a/ui/gfx/mac/coordinate_conversion.h b/ui/gfx/mac/coordinate_conversion.h new file mode 100644 index 0000000..3deec9a --- /dev/null +++ b/ui/gfx/mac/coordinate_conversion.h @@ -0,0 +1,26 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_GFX_MAC_COORDINATE_CONVERSION_H_ +#define UI_GFX_MAC_COORDINATE_CONVERSION_H_ + +#import <Foundation/Foundation.h> + +#include "ui/gfx/gfx_export.h" + +namespace gfx { + +class Rect; + +// Convert a gfx::Rect specified with the origin at the top left of the primary +// display into AppKit secreen coordinates (origin at the bottom left). +GFX_EXPORT NSRect ScreenRectToNSRect(const gfx::Rect& rect); + +// Convert an AppKit NSRect with origin in the bottom left of the primary +// display into a gfx::Rect with origin at the top left of the primary display. +GFX_EXPORT gfx::Rect ScreenRectFromNSRect(const NSRect& point); + +} // namespace gfx + +#endif // UI_GFX_MAC_COORDINATE_CONVERSION_H_ diff --git a/ui/gfx/mac/coordinate_conversion.mm b/ui/gfx/mac/coordinate_conversion.mm new file mode 100644 index 0000000..b2c41a4 --- /dev/null +++ b/ui/gfx/mac/coordinate_conversion.mm @@ -0,0 +1,37 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#import "ui/gfx/mac/coordinate_conversion.h" + +#import <Cocoa/Cocoa.h> + +#include "ui/gfx/geometry/rect.h" + +namespace gfx { + +namespace { + +// The height of the primary display, which OSX defines as the monitor with the +// menubar. This is always at index 0. +CGFloat PrimaryDisplayHeight() { + return NSMaxY([[[NSScreen screens] objectAtIndex:0] frame]); +} + +} // namespace + +NSRect ScreenRectToNSRect(const gfx::Rect& rect) { + return NSMakeRect(rect.x(), + PrimaryDisplayHeight() - rect.y() - rect.height(), + rect.width(), + rect.height()); +} + +gfx::Rect ScreenRectFromNSRect(const NSRect& rect) { + return gfx::Rect(rect.origin.x, + PrimaryDisplayHeight() - rect.origin.y - rect.size.height, + rect.size.width, + rect.size.height); +} + +} // namespace gfx |