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