OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <QuartzCore/QuartzCore.h> | 5 #include <QuartzCore/QuartzCore.h> |
6 | 6 |
7 #include "chrome/browser/renderer_host/render_widget_host_view_mac.h" | 7 #include "chrome/browser/renderer_host/render_widget_host_view_mac.h" |
8 | 8 |
9 #include "app/app_switches.h" | 9 #include "app/app_switches.h" |
10 #include "app/surface/io_surface_support_mac.h" | 10 #include "app/surface/io_surface_support_mac.h" |
(...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
665 // ignore them so we don't re-allocate the backing store. We will paint | 665 // ignore them so we don't re-allocate the backing store. We will paint |
666 // everything again when we become selected again. | 666 // everything again when we become selected again. |
667 is_hidden_ = true; | 667 is_hidden_ = true; |
668 | 668 |
669 // If we have a renderer, then inform it that we are being hidden so it can | 669 // If we have a renderer, then inform it that we are being hidden so it can |
670 // reduce its resource utilization. | 670 // reduce its resource utilization. |
671 render_widget_host_->WasHidden(); | 671 render_widget_host_->WasHidden(); |
672 } | 672 } |
673 | 673 |
674 void RenderWidgetHostViewMac::SetSize(const gfx::Size& size) { | 674 void RenderWidgetHostViewMac::SetSize(const gfx::Size& size) { |
| 675 gfx::Rect rect = GetViewBounds(); |
| 676 rect.set_size(size); |
| 677 SetBounds(rect); |
| 678 } |
| 679 |
| 680 void RenderWidgetHostViewMac::SetBounds(const gfx::Rect& rect) { |
| 681 // |rect.size()| is view coordinates, |rect.origin| is screen coordinates, |
| 682 // TODO(thakis): fix, http://crbug.com/73362 |
675 if (is_hidden_) | 683 if (is_hidden_) |
676 return; | 684 return; |
677 | 685 |
678 // During the initial creation of the RenderWidgetHostView in | 686 // During the initial creation of the RenderWidgetHostView in |
679 // TabContents::CreateRenderViewForRenderManager, SetSize is called with an | 687 // TabContents::CreateRenderViewForRenderManager, SetSize is called with an |
680 // empty size. In the Windows code flow, it is not ignored because subsequent | 688 // empty size. In the Windows code flow, it is not ignored because subsequent |
681 // sizing calls from the OS flow through TCVW::WasSized which calls SetSize() | 689 // sizing calls from the OS flow through TCVW::WasSized which calls SetSize() |
682 // again. On Cocoa, we rely on the Cocoa view struture and resizer flags to | 690 // again. On Cocoa, we rely on the Cocoa view struture and resizer flags to |
683 // keep things sized properly. On the other hand, if the size is not empty | 691 // keep things sized properly. On the other hand, if the size is not empty |
684 // then this is a valid request for a pop-up. | 692 // then this is a valid request for a pop-up. |
685 if (size.IsEmpty()) | 693 if (rect.size().IsEmpty()) |
686 return; | 694 return; |
687 | 695 |
688 // Do conversions to upper-left origin, as "set size" means keep the | 696 // The position of |rect| is screen coordnate system and we have to consider |
689 // upper-left corner pinned. If the new size is valid, this is a popup whose | 697 // Cocoa coordinate system is upside-down and also muti screen. |
690 // superview is another RenderWidgetHostViewCocoa, but even if it's directly | 698 NSPoint global_origin = NSPointFromCGPoint(rect.origin().ToCGPoint()); |
691 // in a TabContentsViewCocoa, they're both BaseViews. | 699 if ([[NSScreen screens] count] > 0) { |
692 DCHECK([[cocoa_view_ superview] isKindOfClass:[BaseView class]]); | 700 NSSize size = NSMakeSize(rect.width(), rect.height()); |
693 gfx::Rect rect = | 701 size = [cocoa_view_ convertSize:size toView:nil]; |
694 [(BaseView*)[cocoa_view_ superview] flipNSRectToRect:[cocoa_view_ frame]]; | 702 NSScreen* screen = |
695 rect.set_width(size.width()); | 703 static_cast<NSScreen*>([[NSScreen screens] objectAtIndex:0]); |
696 rect.set_height(size.height()); | 704 global_origin.y = NSHeight([screen frame]) - size.height - global_origin.y; |
697 [cocoa_view_ setFrame: | 705 } |
698 [(BaseView*)[cocoa_view_ superview] flipRectToNSRect:rect]]; | 706 |
| 707 // Then |global_origin| is converted to client coordinate system. |
| 708 NSPoint window_origin = |
| 709 [[cocoa_view_ window] convertScreenToBase:global_origin]; |
| 710 NSRect frame = NSMakeRect(window_origin.x, window_origin.y, |
| 711 rect.width(), rect.height()); |
| 712 [cocoa_view_ setFrame:frame]; |
699 } | 713 } |
700 | 714 |
701 gfx::NativeView RenderWidgetHostViewMac::GetNativeView() { | 715 gfx::NativeView RenderWidgetHostViewMac::GetNativeView() { |
702 return native_view(); | 716 return native_view(); |
703 } | 717 } |
704 | 718 |
705 void RenderWidgetHostViewMac::MovePluginWindows( | 719 void RenderWidgetHostViewMac::MovePluginWindows( |
706 const std::vector<webkit::npapi::WebPluginGeometry>& moves) { | 720 const std::vector<webkit::npapi::WebPluginGeometry>& moves) { |
707 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 721 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
708 // Handle movement of accelerated plugins, which are the only "windowed" | 722 // Handle movement of accelerated plugins, which are the only "windowed" |
(...skipping 2120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2829 if (!string) return NO; | 2843 if (!string) return NO; |
2830 | 2844 |
2831 // If the user is currently using an IME, confirm the IME input, | 2845 // If the user is currently using an IME, confirm the IME input, |
2832 // and then insert the text from the service, the same as TextEdit and Safari. | 2846 // and then insert the text from the service, the same as TextEdit and Safari. |
2833 [self confirmComposition]; | 2847 [self confirmComposition]; |
2834 [self insertText:string]; | 2848 [self insertText:string]; |
2835 return YES; | 2849 return YES; |
2836 } | 2850 } |
2837 | 2851 |
2838 @end | 2852 @end |
OLD | NEW |