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

Unified Diff: ui/views/widget/native_widget_mac.mm

Issue 659233002: STASH: Epic Experimental patch for toolkit-views App List on Mac Base URL: https://chromium.googlesource.com/chromium/src.git/+/master
Patch Set: Fix a few things. Works@master Created 6 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/views/widget/native_widget_mac.h ('k') | ui/views/widget/native_widget_mac_unittest.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/widget/native_widget_mac.mm
diff --git a/ui/views/widget/native_widget_mac.mm b/ui/views/widget/native_widget_mac.mm
index b6aa7176a1163772804329ac8577fa0cf8146f31..4f4a52127f4e5fcf2e9bf83098ce26bb07a6a29e 100644
--- a/ui/views/widget/native_widget_mac.mm
+++ b/ui/views/widget/native_widget_mac.mm
@@ -7,10 +7,12 @@
#import <Cocoa/Cocoa.h>
#include "base/mac/foundation_util.h"
+#import "base/mac/sdk_forward_declarations.h"
#include "base/mac/scoped_nsobject.h"
#include "base/strings/sys_string_conversions.h"
#include "ui/gfx/font_list.h"
#import "ui/gfx/mac/coordinate_conversion.h"
+#include "ui/gfx/screen.h"
#include "ui/native_theme/native_theme.h"
#import "ui/views/cocoa/bridged_content_view.h"
#import "ui/views/cocoa/bridged_native_widget.h"
@@ -33,8 +35,11 @@
return YES;
}
+// Also override canBecomeMainWindow, but ensure that transient child windows
+// do not achieve main status, even if key. Main status should stay with the
+// parent window.
- (BOOL)canBecomeMainWindow {
- return YES;
+ return ![[self viewsNSWindowDelegate] isTransientChild];
}
// Override orderWindow to intercept visibility changes, since there is no way
@@ -43,7 +48,7 @@
relativeTo:(NSInteger)otherWindowNumber {
[[self viewsNSWindowDelegate] onWindowOrderWillChange:orderingMode];
[super orderWindow:orderingMode relativeTo:otherWindowNumber];
- [[self viewsNSWindowDelegate] onWindowOrderChanged];
+ [[self viewsNSWindowDelegate] onWindowOrderChanged:nil];
}
@end
@@ -77,7 +82,9 @@ NSRect ValidateContentRect(NSRect content_rect) {
}
gfx::Size WindowSizeForClientAreaSize(NSWindow* window, const gfx::Size& size) {
- NSRect content_rect = NSMakeRect(0, 0, size.width(), size.height());
+ DCHECK(window);
+ NSRect content_rect =
+ ValidateContentRect(NSMakeRect(0, 0, size.width(), size.height()));
NSRect frame_rect = [window frameRectForContentRect:content_rect];
return gfx::Size(NSWidth(frame_rect), NSHeight(frame_rect));
}
@@ -146,8 +153,7 @@ bool NativeWidgetMac::ShouldUseNativeFrame() const {
}
bool NativeWidgetMac::ShouldWindowContentsBeTransparent() const {
- NOTIMPLEMENTED();
- return false;
+ return true;
}
void NativeWidgetMac::FrameTypeChanged() {
@@ -177,18 +183,15 @@ Widget* NativeWidgetMac::GetTopLevelWidget() {
}
const ui::Compositor* NativeWidgetMac::GetCompositor() const {
- NOTIMPLEMENTED();
- return NULL;
+ return bridge_->layer() ? bridge_->layer()->GetCompositor() : NULL;
}
ui::Compositor* NativeWidgetMac::GetCompositor() {
- NOTIMPLEMENTED();
- return NULL;
+ return bridge_->layer() ? bridge_->layer()->GetCompositor() : NULL;
}
ui::Layer* NativeWidgetMac::GetLayer() {
- NOTIMPLEMENTED();
- return NULL;
+ return bridge_->GetOrCreateLayer();
}
void NativeWidgetMac::ReorderNativeViews() {
@@ -215,16 +218,20 @@ TooltipManager* NativeWidgetMac::GetTooltipManager() const {
}
void NativeWidgetMac::SetCapture() {
- NOTIMPLEMENTED();
+ // Basic mouse capture to simulate ::SetCapture() from Windows. Capture on OSX
+ // is automatic for mouse drag events. This allows mouse move events to also
+ // be sent to responders, but only when the mouse is over the window. To get
+ // move events outside the window, Mac will need an event tap.
+ [GetNativeWindow() setAcceptsMouseMovedEvents:YES];
+ //[GetNativeWindow() makeKeyWindow];
}
void NativeWidgetMac::ReleaseCapture() {
- NOTIMPLEMENTED();
+ [GetNativeWindow() setAcceptsMouseMovedEvents:NO];
}
bool NativeWidgetMac::HasCapture() const {
- NOTIMPLEMENTED();
- return false;
+ return [GetNativeWindow() acceptsMouseMovedEvents];
}
InputMethod* NativeWidgetMac::CreateInputMethod() {
@@ -247,9 +254,21 @@ void NativeWidgetMac::CenterWindow(const gfx::Size& size) {
[GetNativeWindow() center];
}
-void NativeWidgetMac::GetWindowPlacement(gfx::Rect* bounds,
- ui::WindowShowState* maximized) const {
- NOTIMPLEMENTED();
+void NativeWidgetMac::GetWindowPlacement(
+ gfx::Rect* bounds,
+ ui::WindowShowState* show_state) const {
+ *bounds = GetRestoredBounds();
+ if (IsMinimized()) {
+ *show_state = ui::SHOW_STATE_MINIMIZED;
+ return;
+ }
+
+ if (IsFullscreen()) {
+ *show_state = ui::SHOW_STATE_FULLSCREEN;
+ return;
+ }
+
+ *show_state = ui::SHOW_STATE_DEFAULT;
}
bool NativeWidgetMac::SetWindowTitle(const base::string16& title) {
@@ -287,9 +306,20 @@ gfx::Rect NativeWidgetMac::GetRestoredBounds() const {
}
void NativeWidgetMac::SetBounds(const gfx::Rect& bounds) {
+#if 1
[GetNativeWindow() setFrame:gfx::ScreenRectToNSRect(bounds)
display:YES
animate:NO];
+ if (!IsVisible()) {
+ // If not visible, notifications do not come from Cocoa, so send our own.
+ //NSSize new_size = [GetNativeWindow() frame].size;
+ //GetWidget()->OnNativeWidgetSizeChanged(
+ // gfx::Size(new_size.width, new_size.height));
+ }
+#else
+ if (bridge_)
+ bridge_->SetBounds(bounds);
+#endif
}
void NativeWidgetMac::SetSize(const gfx::Size& size) {
@@ -340,7 +370,7 @@ void NativeWidgetMac::Show() {
}
void NativeWidgetMac::Hide() {
- NOTIMPLEMENTED();
+ [GetNativeWindow() orderOut:nil];
}
void NativeWidgetMac::ShowMaximizedWithBounds(
@@ -428,7 +458,13 @@ void NativeWidgetMac::Maximize() {
}
void NativeWidgetMac::Minimize() {
- NOTIMPLEMENTED();
+ NSWindow* window = GetNativeWindow();
+ // Calling performMiniaturize: will momentarily highlight the button, but
+ // AppKit will reject it if there is no miniaturize button.
+ if ([window styleMask] & NSMiniaturizableWindowMask)
+ [window performMiniaturize:nil];
+ else
+ [window miniaturize:nil];
}
bool NativeWidgetMac::IsMaximized() const {
@@ -438,12 +474,11 @@ bool NativeWidgetMac::IsMaximized() const {
}
bool NativeWidgetMac::IsMinimized() const {
- NOTIMPLEMENTED();
- return false;
+ return [GetNativeWindow() isMiniaturized];
}
void NativeWidgetMac::Restore() {
- NOTIMPLEMENTED();
+ [GetNativeWindow() deminiaturize:nil];
}
void NativeWidgetMac::SetFullscreen(bool fullscreen) {
@@ -481,6 +516,9 @@ void NativeWidgetMac::SchedulePaintInRect(const gfx::Rect& rect) {
// TODO(tapted): This should use setNeedsDisplayInRect:, once the coordinate
// system of |rect| has been converted.
[GetNativeView() setNeedsDisplay:YES];
+ if (bridge_ && bridge_->layer()) {
+ bridge_->layer()->SchedulePaint(rect);
+ }
}
void NativeWidgetMac::SetCursor(gfx::NativeCursor cursor) {
@@ -497,8 +535,12 @@ void NativeWidgetMac::ClearNativeFocus() {
}
gfx::Rect NativeWidgetMac::GetWorkAreaBoundsInScreen() const {
- NOTIMPLEMENTED();
- return gfx::Rect();
+ NSView* view = GetNativeView();
+ if (!view)
+ return gfx::Rect();
+ return gfx::Screen::GetScreenFor(view)
+ ->GetDisplayNearestWindow(view)
+ .work_area();
}
Widget::MoveLoopResult NativeWidgetMac::RunMoveLoop(
« no previous file with comments | « ui/views/widget/native_widget_mac.h ('k') | ui/views/widget/native_widget_mac_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698