diff options
author | avi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-17 22:04:50 +0000 |
---|---|---|
committer | avi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-17 22:04:50 +0000 |
commit | 98f8d9c1248dc678ef09af9436976ca5af72f42a (patch) | |
tree | 81bc7d0de54f586d15cdb978270b43c53afb64cf | |
parent | 401efff5d553c57124790696503f0f06fff31344 (diff) | |
download | chromium_src-98f8d9c1248dc678ef09af9436976ca5af72f42a.zip chromium_src-98f8d9c1248dc678ef09af9436976ca5af72f42a.tar.gz chromium_src-98f8d9c1248dc678ef09af9436976ca5af72f42a.tar.bz2 |
Significantly rework coordinate handling for the Cocoa views. Fixes tons of redraw and scrolling issues.
Review URL: http://codereview.chromium.org/20435
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@9905 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/cocoa/base_view.h | 34 | ||||
-rw-r--r-- | chrome/browser/cocoa/base_view.mm (renamed from chrome/browser/cocoa/event_view.mm) | 17 | ||||
-rw-r--r-- | chrome/browser/cocoa/event_view.h | 25 | ||||
-rw-r--r-- | chrome/browser/cocoa/sad_tab_view.h | 4 | ||||
-rw-r--r-- | chrome/browser/renderer_host/render_widget_host_view_mac.h | 6 | ||||
-rw-r--r-- | chrome/browser/renderer_host/render_widget_host_view_mac.mm | 29 | ||||
-rw-r--r-- | chrome/browser/tab_contents/web_contents_view_mac.h | 3 | ||||
-rw-r--r-- | chrome/browser/tab_contents/web_contents_view_mac.mm | 6 | ||||
-rw-r--r-- | chrome/chrome.xcodeproj/project.pbxproj | 12 |
9 files changed, 81 insertions, 55 deletions
diff --git a/chrome/browser/cocoa/base_view.h b/chrome/browser/cocoa/base_view.h new file mode 100644 index 0000000..5147451 --- /dev/null +++ b/chrome/browser/cocoa/base_view.h @@ -0,0 +1,34 @@ +// Copyright (c) 2009 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 CHROME_BROWSER_COCOA_BASE_VIEW_H_ +#define CHROME_BROWSER_COCOA_BASE_VIEW_H_ + +#import <Cocoa/Cocoa.h> + +#include "base/gfx/rect.h" + +// A view that provides common functionality that many views will need: +// - Automatic registration for mouse-moved events. +// - Funneling of mouse and key events to two methods +// - Coordinate conversion utilities + +@interface BaseView : NSView { + @private + NSTrackingArea *trackingArea_; +} + +- (id)initWithFrame:(NSRect)frame; + +// Override these methods in a subclass. +- (void)mouseEvent:(NSEvent *)theEvent; +- (void)keyEvent:(NSEvent *)theEvent; + +// Useful rect conversions (doing coordinate flipping) +- (gfx::Rect)NSRectToRect:(NSRect)rect; +- (NSRect)RectToNSRect:(gfx::Rect)rect; + +@end + +#endif // CHROME_BROWSER_COCOA_BASE_VIEW_H_ diff --git a/chrome/browser/cocoa/event_view.mm b/chrome/browser/cocoa/base_view.mm index 3cb4c44..9d8e247 100644 --- a/chrome/browser/cocoa/event_view.mm +++ b/chrome/browser/cocoa/base_view.mm @@ -2,9 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/cocoa/event_view.h" +#include "chrome/browser/cocoa/base_view.h" -@implementation EventView +@implementation BaseView - (id)initWithFrame:(NSRect)frame { self = [super initWithFrame:frame]; @@ -96,4 +96,17 @@ return YES; } +- (gfx::Rect)NSRectToRect:(NSRect)rect { + gfx::Rect new_rect(NSRectToCGRect(rect)); + new_rect.set_y([self bounds].size.height - new_rect.y() - new_rect.height()); + return new_rect; +} + +- (NSRect)RectToNSRect:(gfx::Rect)rect { + NSRect new_rect(NSRectFromCGRect(rect.ToCGRect())); + new_rect.origin.y = + [self bounds].size.height - new_rect.origin.y - new_rect.size.height; + return new_rect; +} + @end diff --git a/chrome/browser/cocoa/event_view.h b/chrome/browser/cocoa/event_view.h deleted file mode 100644 index fc49232..0000000 --- a/chrome/browser/cocoa/event_view.h +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (c) 2009 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 CHROME_BROWSER_COCOA_EVENT_VIEW_H_ -#define CHROME_BROWSER_COCOA_EVENT_VIEW_H_ - -#import <Cocoa/Cocoa.h> - -// A view that registers for mouse move events, and funnels all events. - -@interface EventView : NSView { - @private - NSTrackingArea *trackingArea_; -} - -- (id)initWithFrame:(NSRect)frame; - -// Override these methods in a subclass. -- (void)mouseEvent:(NSEvent *)theEvent; -- (void)keyEvent:(NSEvent *)theEvent; - -@end - -#endif // CHROME_BROWSER_COCOA_EVENT_VIEW_H_ diff --git a/chrome/browser/cocoa/sad_tab_view.h b/chrome/browser/cocoa/sad_tab_view.h index ffe57a5..d003536 100644 --- a/chrome/browser/cocoa/sad_tab_view.h +++ b/chrome/browser/cocoa/sad_tab_view.h @@ -5,13 +5,13 @@ #ifndef CHROME_BROWSER_COCOA_SAD_TAB_VIEW_H_ #define CHROME_BROWSER_COCOA_SAD_TAB_VIEW_H_ -#include "chrome/browser/cocoa/event_view.h" +#include "chrome/browser/cocoa/base_view.h" #import <Cocoa/Cocoa.h> // A view that displays the "sad tab". -@interface SadTabView : EventView { +@interface SadTabView : BaseView { @private } diff --git a/chrome/browser/renderer_host/render_widget_host_view_mac.h b/chrome/browser/renderer_host/render_widget_host_view_mac.h index 073573d..a9221c9 100644 --- a/chrome/browser/renderer_host/render_widget_host_view_mac.h +++ b/chrome/browser/renderer_host/render_widget_host_view_mac.h @@ -8,18 +8,18 @@ #import <Cocoa/Cocoa.h> #include "base/time.h" -#include "chrome/browser/cocoa/event_view.h" +#include "chrome/browser/cocoa/base_view.h" #include "chrome/browser/renderer_host/render_widget_host_view.h" #include "webkit/glue/webcursor.h" class RenderWidgetHostViewMac; -// This is the NSView that lives in the Cocoa view hierarchy. In Windows-land, +// This is the view that lives in the Cocoa view hierarchy. In Windows-land, // RenderWidgetHostViewWin is both the view and the delegate. We split the roles // but that means that the view needs to own the delegate and will dispose of it // when it's removed from the view system. -@interface RenderWidgetHostViewCocoa : EventView { +@interface RenderWidgetHostViewCocoa : BaseView { @private RenderWidgetHostViewMac* renderWidgetHostView_; } diff --git a/chrome/browser/renderer_host/render_widget_host_view_mac.mm b/chrome/browser/renderer_host/render_widget_host_view_mac.mm index 968f5e0..fd782e7 100644 --- a/chrome/browser/renderer_host/render_widget_host_view_mac.mm +++ b/chrome/browser/renderer_host/render_widget_host_view_mac.mm @@ -80,9 +80,7 @@ void RenderWidgetHostViewMac::SetSize(const gfx::Size& size) { if (is_hidden_) return; - NSRect rect = [cocoa_view_ frame]; - rect.size = NSSizeFromCGSize(size.ToCGSize()); - [cocoa_view_ setFrame:rect]; + NOTIMPLEMENTED(); // Who is trying to force a size? We're a Cocoa view. } gfx::NativeView RenderWidgetHostViewMac::GetPluginNativeView() { @@ -121,7 +119,7 @@ void RenderWidgetHostViewMac::Hide() { } gfx::Rect RenderWidgetHostViewMac::GetViewBounds() const { - return gfx::Rect(NSRectToCGRect([cocoa_view_ frame])); + return [cocoa_view_ NSRectToRect:[cocoa_view_ bounds]]; } void RenderWidgetHostViewMac::UpdateCursor(const WebCursor& cursor) { @@ -159,7 +157,7 @@ void RenderWidgetHostViewMac::IMEUpdateStatus(int control, } void RenderWidgetHostViewMac::Redraw(const gfx::Rect& rect) { - [cocoa_view_ setNeedsDisplayInRect:NSRectFromCGRect(rect.ToCGRect())]; + [cocoa_view_ setNeedsDisplayInRect:[cocoa_view_ RectToNSRect:rect]]; } void RenderWidgetHostViewMac::DidPaintRect(const gfx::Rect& rect) { @@ -173,9 +171,14 @@ void RenderWidgetHostViewMac::DidScrollRect( const gfx::Rect& rect, int dx, int dy) { if (is_hidden_) return; + + [cocoa_view_ scrollRect:[cocoa_view_ RectToNSRect:rect] + by:NSMakeSize(dx, -dy)]; - [cocoa_view_ scrollRect:NSRectFromCGRect(rect.ToCGRect()) - by:NSMakeSize(dx, dy)]; + gfx::Rect new_rect = rect; + new_rect.Offset(dx, dy); + gfx::Rect dirty_rect = rect.Subtract(new_rect); + [cocoa_view_ setNeedsDisplayInRect:[cocoa_view_ RectToNSRect:dirty_rect]]; } void RenderWidgetHostViewMac::RendererGone() { @@ -257,20 +260,22 @@ void RenderWidgetHostViewMac::ShutdownHost() { skia::PlatformCanvas* canvas = backing_store->canvas(); if (backing_store) { - gfx::Rect damaged_rect(NSRectToCGRect(dirtyRect)); + gfx::Rect damaged_rect([self NSRectToRect:dirtyRect]); - gfx::Rect bitmap_rect( - 0, 0, backing_store->size().width(), backing_store->size().height()); + gfx::Rect bitmap_rect(0, 0, + backing_store->size().width(), + backing_store->size().height()); gfx::Rect paint_rect = bitmap_rect.Intersect(damaged_rect); if (!paint_rect.IsEmpty()) { if ([self lockFocusIfCanDraw]) { CGContextRef context = static_cast<CGContextRef>( [[NSGraphicsContext currentContext] graphicsPort]); - + CGRect damaged_rect_cg = damaged_rect.ToCGRect(); + NSRect damaged_rect_ns = [self RectToNSRect:damaged_rect]; canvas->getTopPlatformDevice().DrawToContext( - context, damaged_rect.x(), damaged_rect.y(), + context, damaged_rect_ns.origin.x, damaged_rect_ns.origin.y, &damaged_rect_cg); [self unlockFocus]; diff --git a/chrome/browser/tab_contents/web_contents_view_mac.h b/chrome/browser/tab_contents/web_contents_view_mac.h index 1ea5144..d576605 100644 --- a/chrome/browser/tab_contents/web_contents_view_mac.h +++ b/chrome/browser/tab_contents/web_contents_view_mac.h @@ -9,13 +9,14 @@ #include "base/gfx/size.h" #include "base/scoped_cftyperef.h" +#include "chrome/browser/cocoa/base_view.h" #include "chrome/browser/tab_contents/web_contents_view.h" #include "chrome/common/notification_registrar.h" class FindBarMac; @class SadTabView; -@interface WebContentsViewCocoa : NSView { +@interface WebContentsViewCocoa : BaseView { } @end diff --git a/chrome/browser/tab_contents/web_contents_view_mac.mm b/chrome/browser/tab_contents/web_contents_view_mac.mm index e59338a..ba80b54 100644 --- a/chrome/browser/tab_contents/web_contents_view_mac.mm +++ b/chrome/browser/tab_contents/web_contents_view_mac.mm @@ -73,7 +73,7 @@ gfx::NativeWindow WebContentsViewMac::GetTopLevelNativeView() const { } void WebContentsViewMac::GetContainerBounds(gfx::Rect* out) const { - *out = gfx::Rect(NSRectToCGRect([cocoa_view_.get() frame])); + *out = [cocoa_view_.get() NSRectToRect:[cocoa_view_.get() bounds]]; } void WebContentsViewMac::StartDragging(const WebDropData& drop_data) { @@ -96,9 +96,7 @@ void WebContentsViewMac::Invalidate() { void WebContentsViewMac::SizeContents(const gfx::Size& size) { // TODO(brettw) this is a hack and should be removed. See web_contents_view.h. - NSRect rect = [cocoa_view_.get() frame]; - rect.size = NSSizeFromCGSize(size.ToCGSize()); - [cocoa_view_.get() setBounds:rect]; + NOTIMPLEMENTED(); // Leaving the hack unimplemented. } void WebContentsViewMac::FindInPage(const Browser& browser, diff --git a/chrome/chrome.xcodeproj/project.pbxproj b/chrome/chrome.xcodeproj/project.pbxproj index 817b271..50e9759 100644 --- a/chrome/chrome.xcodeproj/project.pbxproj +++ b/chrome/chrome.xcodeproj/project.pbxproj @@ -281,7 +281,7 @@ 826858470F325A10009F6555 /* template_url_unittest.cc in Sources */ = {isa = PBXBuildFile; fileRef = B5D16EE60F21455600861FAC /* template_url_unittest.cc */; }; 8268589C0F326CCC009F6555 /* template_url_parser_unittest.cc in Sources */ = {isa = PBXBuildFile; fileRef = B5D16EE20F21455600861FAC /* template_url_parser_unittest.cc */; }; 826858FA0F326FA3009F6555 /* testing_profile.cc in Sources */ = {isa = PBXBuildFile; fileRef = 826858F80F326FA3009F6555 /* testing_profile.cc */; }; - 82BB330A0F44B57C00761F43 /* event_view.mm in Sources */ = {isa = PBXBuildFile; fileRef = 82BB33090F44B57C00761F43 /* event_view.mm */; }; + 82BB330A0F44B57C00761F43 /* base_view.mm in Sources */ = {isa = PBXBuildFile; fileRef = 82BB33090F44B57C00761F43 /* base_view.mm */; }; 82FA32330F3A4CC400271C5A /* web_contents_view.cc in Sources */ = {isa = PBXBuildFile; fileRef = B6CCB9F20F1EC32700106F0D /* web_contents_view.cc */; }; 82FA32760F3A537C00271C5A /* web_contents_view_mac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 82FA32750F3A537C00271C5A /* web_contents_view_mac.mm */; }; 82FA33460F3A7F6900271C5A /* render_widget_host_view_mac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 82FA33450F3A7F6900271C5A /* render_widget_host_view_mac.mm */; }; @@ -2421,8 +2421,8 @@ 826850600F2FCC27009F6555 /* libxslt.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = libxslt.xcodeproj; path = third_party/libxslt/libxslt.xcodeproj; sourceTree = "<group>"; }; 826858F80F326FA3009F6555 /* testing_profile.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = testing_profile.cc; sourceTree = "<group>"; }; 826858F90F326FA3009F6555 /* testing_profile.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = testing_profile.h; sourceTree = "<group>"; }; - 82BB33080F44B57C00761F43 /* event_view.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = event_view.h; path = cocoa/event_view.h; sourceTree = "<group>"; }; - 82BB33090F44B57C00761F43 /* event_view.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = event_view.mm; path = cocoa/event_view.mm; sourceTree = "<group>"; }; + 82BB33080F44B57C00761F43 /* base_view.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = base_view.h; path = cocoa/base_view.h; sourceTree = "<group>"; }; + 82BB33090F44B57C00761F43 /* base_view.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = base_view.mm; path = cocoa/base_view.mm; sourceTree = "<group>"; }; 82FA32740F3A537C00271C5A /* web_contents_view_mac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = web_contents_view_mac.h; path = tab_contents/web_contents_view_mac.h; sourceTree = "<group>"; }; 82FA32750F3A537C00271C5A /* web_contents_view_mac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = web_contents_view_mac.mm; path = tab_contents/web_contents_view_mac.mm; sourceTree = "<group>"; }; 82FA33440F3A7F6900271C5A /* render_widget_host_view_mac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = render_widget_host_view_mac.h; path = renderer_host/render_widget_host_view_mac.h; sourceTree = "<group>"; }; @@ -4372,8 +4372,8 @@ E46C50D10F292E9B00B393B8 /* cocoa */ = { isa = PBXGroup; children = ( - 82BB33080F44B57C00761F43 /* event_view.h */, - 82BB33090F44B57C00761F43 /* event_view.mm */, + 82BB33080F44B57C00761F43 /* base_view.h */, + 82BB33090F44B57C00761F43 /* base_view.mm */, 824FC1550F44C59C000299E5 /* sad_tab_view.h */, 824FC1540F44C59C000299E5 /* sad_tab_view.mm */, A7CBAD370F322A7E00360BF5 /* shell_dialogs_mac.mm */, @@ -5354,6 +5354,7 @@ 671555F7DF06E224B646E5D2 /* backing_store_posix.cc in Sources */, E40CC5EE0F2E34C100708647 /* base_history_model.cc in Sources */, A146CA143D6DE43AF768CF47 /* base_session_service.cc in Sources */, + 82BB330A0F44B57C00761F43 /* base_view.mm in Sources */, 4D7BFAEE0E9D49E5009A6919 /* bloom_filter.cc in Sources */, E45075B20F1505C0003BE099 /* bookmark_codec.cc in Sources */, E40CC5F20F2E34EE00708647 /* bookmark_folder_tree_model.cc in Sources */, @@ -5400,7 +5401,6 @@ E4F324550EE5CFB1002533CE /* download_database.cc in Sources */, E43A77170F16616E00ABD5D1 /* download_resource_handler.cc in Sources */, E45075E30F150A6F003BE099 /* download_throttling_resource_handler.cc in Sources */, - 82BB330A0F44B57C00761F43 /* event_view.mm in Sources */, E4F324470EE5CF1F002533CE /* expire_history_backend.cc in Sources */, E4F324430EE5CE94002533CE /* extension.cc in Sources */, E48B6C280F2783E9002E47EC /* extension_protocols.cc in Sources */, |