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 "content/browser/renderer_host/render_widget_host_view_mac.h" | 5 #include "content/browser/renderer_host/render_widget_host_view_mac.h" |
6 | 6 |
7 #include <QuartzCore/QuartzCore.h> | 7 #include <QuartzCore/QuartzCore.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
152 + (BOOL)shouldAutohideCursorForEvent:(NSEvent*)event; | 152 + (BOOL)shouldAutohideCursorForEvent:(NSEvent*)event; |
153 - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r; | 153 - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r; |
154 - (void)setRWHVDelegate:(NSObject<RenderWidgetHostViewMacDelegate>*)delegate; | 154 - (void)setRWHVDelegate:(NSObject<RenderWidgetHostViewMacDelegate>*)delegate; |
155 - (void)gotUnhandledWheelEvent; | 155 - (void)gotUnhandledWheelEvent; |
156 - (void)scrollOffsetPinnedToLeft:(BOOL)left toRight:(BOOL)right; | 156 - (void)scrollOffsetPinnedToLeft:(BOOL)left toRight:(BOOL)right; |
157 - (void)setHasHorizontalScrollbar:(BOOL)has_horizontal_scrollbar; | 157 - (void)setHasHorizontalScrollbar:(BOOL)has_horizontal_scrollbar; |
158 - (void)keyEvent:(NSEvent*)theEvent wasKeyEquivalent:(BOOL)equiv; | 158 - (void)keyEvent:(NSEvent*)theEvent wasKeyEquivalent:(BOOL)equiv; |
159 - (void)cancelChildPopups; | 159 - (void)cancelChildPopups; |
160 - (void)windowDidChangeBackingProperties:(NSNotification*)notification; | 160 - (void)windowDidChangeBackingProperties:(NSNotification*)notification; |
161 - (void)checkForPluginImeCancellation; | 161 - (void)checkForPluginImeCancellation; |
162 - (void)updateTabBackingStoreScaleFactor; | |
162 @end | 163 @end |
163 | 164 |
164 // NSEvent subtype for scroll gestures events. | 165 // NSEvent subtype for scroll gestures events. |
165 static const short kIOHIDEventTypeScroll = 6; | 166 static const short kIOHIDEventTypeScroll = 6; |
166 | 167 |
167 // A window subclass that allows the fullscreen window to become main and gain | 168 // A window subclass that allows the fullscreen window to become main and gain |
168 // keyboard focus. This is only used for pepper flash. Normal fullscreen is | 169 // keyboard focus. This is only used for pepper flash. Normal fullscreen is |
169 // handled by the browser. | 170 // handled by the browser. |
170 @interface PepperFlashFullscreenWindow : UnderlayOpenGLHostingWindow | 171 @interface PepperFlashFullscreenWindow : UnderlayOpenGLHostingWindow |
171 @end | 172 @end |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
392 } | 393 } |
393 | 394 |
394 RenderWidgetHost* RenderWidgetHostViewMac::GetRenderWidgetHost() const { | 395 RenderWidgetHost* RenderWidgetHostViewMac::GetRenderWidgetHost() const { |
395 return render_widget_host_; | 396 return render_widget_host_; |
396 } | 397 } |
397 | 398 |
398 void RenderWidgetHostViewMac::DidBecomeSelected() { | 399 void RenderWidgetHostViewMac::DidBecomeSelected() { |
399 if (!is_hidden_) | 400 if (!is_hidden_) |
400 return; | 401 return; |
401 | 402 |
403 // Check if the backing scale factor changed while the tab was in the | |
404 // background. | |
405 [cocoa_view_ updateTabBackingStoreScaleFactor]; | |
406 | |
402 if (web_contents_switch_paint_time_.is_null()) | 407 if (web_contents_switch_paint_time_.is_null()) |
403 web_contents_switch_paint_time_ = base::TimeTicks::Now(); | 408 web_contents_switch_paint_time_ = base::TimeTicks::Now(); |
404 is_hidden_ = false; | 409 is_hidden_ = false; |
405 render_widget_host_->WasRestored(); | 410 render_widget_host_->WasRestored(); |
406 | 411 |
407 // We're messing with the window, so do this to ensure no flashes. | 412 // We're messing with the window, so do this to ensure no flashes. |
408 [[cocoa_view_ window] disableScreenUpdatesUntilFlush]; | 413 [[cocoa_view_ window] disableScreenUpdatesUntilFlush]; |
409 } | 414 } |
410 | 415 |
411 void RenderWidgetHostViewMac::WasHidden() { | 416 void RenderWidgetHostViewMac::WasHidden() { |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
813 web_event.type = WebInputEvent::MouseLeave; | 818 web_event.type = WebInputEvent::MouseLeave; |
814 ForwardMouseEvent(web_event); | 819 ForwardMouseEvent(web_event); |
815 } | 820 } |
816 | 821 |
817 bool RenderWidgetHostViewMac::IsPopup() const { | 822 bool RenderWidgetHostViewMac::IsPopup() const { |
818 return popup_type_ != WebKit::WebPopupTypeNone; | 823 return popup_type_ != WebKit::WebPopupTypeNone; |
819 } | 824 } |
820 | 825 |
821 BackingStore* RenderWidgetHostViewMac::AllocBackingStore( | 826 BackingStore* RenderWidgetHostViewMac::AllocBackingStore( |
822 const gfx::Size& size) { | 827 const gfx::Size& size) { |
823 // TODO(thakis): Register for backing scale factor change events and pass | |
824 // that on. | |
825 float scale = ScaleFactor(cocoa_view_); | 828 float scale = ScaleFactor(cocoa_view_); |
826 return new BackingStoreMac(render_widget_host_, size, scale); | 829 return new BackingStoreMac(render_widget_host_, size, scale); |
827 } | 830 } |
828 | 831 |
829 void RenderWidgetHostViewMac::CopyFromCompositingSurface( | 832 void RenderWidgetHostViewMac::CopyFromCompositingSurface( |
830 const gfx::Size& size, | 833 const gfx::Size& size, |
831 skia::PlatformCanvas* output, | 834 skia::PlatformCanvas* output, |
832 base::Callback<void(bool)> callback) { | 835 base::Callback<void(bool)> callback) { |
833 base::ScopedClosureRunner scoped_callback_runner(base::Bind(callback, false)); | 836 base::ScopedClosureRunner scoped_callback_runner(base::Bind(callback, false)); |
834 if (!compositing_iosurface_.get() || | 837 if (!compositing_iosurface_.get() || |
(...skipping 1048 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1883 } | 1886 } |
1884 if (newWindow) { | 1887 if (newWindow) { |
1885 [[NSNotificationCenter defaultCenter] | 1888 [[NSNotificationCenter defaultCenter] |
1886 addObserver:self | 1889 addObserver:self |
1887 selector:@selector(windowDidChangeBackingProperties:) | 1890 selector:@selector(windowDidChangeBackingProperties:) |
1888 name:NSWindowDidChangeBackingPropertiesNotification | 1891 name:NSWindowDidChangeBackingPropertiesNotification |
1889 object:newWindow]; | 1892 object:newWindow]; |
1890 } | 1893 } |
1891 } | 1894 } |
1892 | 1895 |
1896 - (void)updateTabBackingStoreScaleFactor { | |
1897 if (!renderWidgetHostView_->render_widget_host_) | |
1898 return; | |
1899 | |
1900 float scaleFactor = ScaleFactor(self); | |
1901 BackingStoreMac* backingStore = static_cast<BackingStoreMac*>( | |
1902 renderWidgetHostView_->render_widget_host_->GetBackingStore(false)); | |
1903 if (backingStore) // NULL in hardware path. | |
1904 backingStore->ScaleFactorChanged(scaleFactor); | |
1905 | |
1906 renderWidgetHostView_->render_widget_host_->SetDeviceScaleFactor( | |
1907 scaleFactor); | |
1908 } | |
1909 | |
1893 // http://developer.apple.com/library/mac/#documentation/GraphicsAnimation/Conce ptual/HighResolutionOSX/CapturingScreenContents/CapturingScreenContents.html#//a pple_ref/doc/uid/TP40012302-CH10-SW4 | 1910 // http://developer.apple.com/library/mac/#documentation/GraphicsAnimation/Conce ptual/HighResolutionOSX/CapturingScreenContents/CapturingScreenContents.html#//a pple_ref/doc/uid/TP40012302-CH10-SW4 |
1894 - (void)windowDidChangeBackingProperties:(NSNotification*)notification { | 1911 - (void)windowDidChangeBackingProperties:(NSNotification*)notification { |
1895 NSWindow* window = (NSWindow*)[notification object]; | 1912 NSWindow* window = (NSWindow*)[notification object]; |
1896 | 1913 |
1897 CGFloat newBackingScaleFactor = [window backingScaleFactor]; | 1914 CGFloat newBackingScaleFactor = [window backingScaleFactor]; |
1898 CGFloat oldBackingScaleFactor = [base::mac::ObjCCast<NSNumber>( | 1915 CGFloat oldBackingScaleFactor = [base::mac::ObjCCast<NSNumber>( |
1899 [[notification userInfo] objectForKey:NSBackingPropertyOldScaleFactorKey]) | 1916 [[notification userInfo] objectForKey:NSBackingPropertyOldScaleFactorKey]) |
1900 doubleValue]; | 1917 doubleValue]; |
1901 if (newBackingScaleFactor != oldBackingScaleFactor) { | 1918 if (newBackingScaleFactor != oldBackingScaleFactor) { |
1902 // TODO(thakis): Tell backing store about new DPI, schedule repaint. | 1919 // Background tabs check if their scale factor changed when they become |
1903 if (renderWidgetHostView_->render_widget_host_) { | 1920 // active, in DidBecomeSelected(). |
Avi (use Gerrit)
2012/06/14 04:51:20
Not for this CL, but we should rename that to DidB
Nico
2012/06/14 04:57:45
There's also a mac-only SetActive(true) call :-) T
| |
1904 renderWidgetHostView_->render_widget_host_->SetDeviceScaleFactor( | 1921 |
1905 newBackingScaleFactor); | 1922 // Allocating a CGLayerRef with the current scale factor immediately from |
1906 } | 1923 // this handler doesn't work. Schedule the backing store update on the |
1924 // next runloop cycle, then things are read for CGLayerRef allocations to | |
1925 // work. | |
1926 [self performSelector:@selector(updateTabBackingStoreScaleFactor) | |
1927 withObject:nil | |
1928 afterDelay:0]; | |
1907 } | 1929 } |
1908 } | 1930 } |
1909 | 1931 |
1910 - (void)globalFrameDidChange:(NSNotification*)notification { | 1932 - (void)globalFrameDidChange:(NSNotification*)notification { |
1911 if (handlingGlobalFrameDidChange_) | 1933 if (handlingGlobalFrameDidChange_) |
1912 return; | 1934 return; |
1913 | 1935 |
1914 handlingGlobalFrameDidChange_ = YES; | 1936 handlingGlobalFrameDidChange_ = YES; |
1915 if (renderWidgetHostView_->compositing_iosurface_.get()) | 1937 if (renderWidgetHostView_->compositing_iosurface_.get()) |
1916 renderWidgetHostView_->compositing_iosurface_->GlobalFrameDidChange(); | 1938 renderWidgetHostView_->compositing_iosurface_->GlobalFrameDidChange(); |
(...skipping 1120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3037 if (!string) return NO; | 3059 if (!string) return NO; |
3038 | 3060 |
3039 // If the user is currently using an IME, confirm the IME input, | 3061 // If the user is currently using an IME, confirm the IME input, |
3040 // and then insert the text from the service, the same as TextEdit and Safari. | 3062 // and then insert the text from the service, the same as TextEdit and Safari. |
3041 [self confirmComposition]; | 3063 [self confirmComposition]; |
3042 [self insertText:string]; | 3064 [self insertText:string]; |
3043 return YES; | 3065 return YES; |
3044 } | 3066 } |
3045 | 3067 |
3046 @end | 3068 @end |
OLD | NEW |