diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-04 05:05:48 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-04 05:05:48 +0000 |
commit | a3406979cd56b42ec58244e6382ca77c2c93205d (patch) | |
tree | 76d2c688df49a6d3dc3d182c86b15ffe5ba9cf8e /app | |
parent | 1111563020b92fc9f6943e0b5c00f66de2f57082 (diff) | |
download | chromium_src-a3406979cd56b42ec58244e6382ca77c2c93205d.zip chromium_src-a3406979cd56b42ec58244e6382ca77c2c93205d.tar.gz chromium_src-a3406979cd56b42ec58244e6382ca77c2c93205d.tar.bz2 |
Attempt 2 at:
Gets find bar animation/clipping to work on views/gtk.
The only difference between this and the first version is fixing an
include in extension_host that was triggering mac to build views, as
well as an extraneous SetSlideDuration I had used for testing.
BUG=none
TEST=none
TBR=ben
Review URL: http://codereview.chromium.org/342116
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@30942 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app')
-rw-r--r-- | app/app.gyp | 1 | ||||
-rw-r--r-- | app/gfx/native_widget_types.h | 3 | ||||
-rw-r--r-- | app/gfx/path.cc | 18 | ||||
-rw-r--r-- | app/gfx/path.h | 43 | ||||
-rw-r--r-- | app/gfx/path_gtk.cc | 23 | ||||
-rw-r--r-- | app/gfx/path_win.cc | 23 | ||||
-rw-r--r-- | app/win_util.h | 1 |
7 files changed, 94 insertions, 18 deletions
diff --git a/app/app.gyp b/app/app.gyp index 7e883f0..e503bd1 100644 --- a/app/app.gyp +++ b/app/app.gyp @@ -115,6 +115,7 @@ 'gfx/native_theme_win.h', 'gfx/gtk_native_view_id_manager.cc', 'gfx/gtk_native_view_id_manager.h', + 'gfx/path.cc', 'gfx/path_gtk.cc', 'gfx/path_win.cc', 'gfx/path.h', diff --git a/app/gfx/native_widget_types.h b/app/gfx/native_widget_types.h index 0153194..eda722d 100644 --- a/app/gfx/native_widget_types.h +++ b/app/gfx/native_widget_types.h @@ -51,6 +51,7 @@ typedef struct _GdkCursor GdkCursor; typedef struct _GtkWidget GtkWidget; typedef struct _GtkWindow GtkWindow; typedef struct _cairo cairo_t; +typedef struct _GdkRegion GdkRegion; #endif namespace gfx { @@ -62,6 +63,7 @@ typedef HWND NativeEditView; typedef HDC NativeDrawingContext; typedef HCURSOR NativeCursor; typedef HMENU NativeMenu; +typedef HRGN NativeRegion; #elif defined(OS_MACOSX) typedef NSView* NativeView; typedef NSWindow* NativeWindow; @@ -76,6 +78,7 @@ typedef GtkWidget* NativeEditView; typedef cairo_t* NativeDrawingContext; typedef GdkCursor* NativeCursor; typedef GtkWidget* NativeMenu; +typedef GdkRegion* NativeRegion; #endif // Note: for test_shell we're packing a pointer into the NativeViewId. So, if diff --git a/app/gfx/path.cc b/app/gfx/path.cc new file mode 100644 index 0000000..b5eeeca --- /dev/null +++ b/app/gfx/path.cc @@ -0,0 +1,18 @@ +// 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. + +#include "app/gfx/path.h" + +#include "base/logging.h" + +namespace gfx { + +Path::Path(const Point* points, size_t count) { + DCHECK(count > 1); + moveTo(SkIntToScalar(points[0].x), SkIntToScalar(points[0].y)); + for (size_t i = 1; i < count; ++i) + lineTo(SkIntToScalar(points[i].x), SkIntToScalar(points[i].y)); +} + +} // namespace gfx diff --git a/app/gfx/path.h b/app/gfx/path.h index e2150c2..bc84ca8 100644 --- a/app/gfx/path.h +++ b/app/gfx/path.h @@ -5,31 +5,44 @@ #ifndef APP_GFX_PATH_H_ #define APP_GFX_PATH_H_ +#include "app/gfx/native_widget_types.h" #include "base/basictypes.h" -#if defined(OS_WIN) -#include <windows.h> -#elif defined(OS_LINUX) -typedef struct _GdkRegion GdkRegion; -#endif - #include "third_party/skia/include/core/SkPath.h" namespace gfx { class Path : public SkPath { public: + // Used by Path(Point,size_t) constructor. + struct Point { + int x; + int y; + }; + Path() : SkPath() { moveTo(0, 0); } -#if defined(OS_WIN) - // Creates a HRGN from the path. The caller is responsible for freeing - // resources used by this region. This only supports polygon paths. - HRGN CreateHRGN() const; -#elif defined(OS_LINUX) - // Creates a Gdkregion from the path. The caller is responsible for freeing - // resources used by this region. This only supports polygon paths. - // WARNING: this returns NULL for an empty Path. - GdkRegion* CreateGdkRegion() const; + // Creates a path populated with the specified points. + Path(const Point* points, size_t count); + +#if defined(OS_WIN) || defined(USE_X11) + // Creates a NativeRegion from the path. The caller is responsible for freeing + // resources used by this region. This only supports polygon paths. + NativeRegion CreateNativeRegion() const; + + // Returns the intersection of the two regions. The caller owns the returned + // object. + static gfx::NativeRegion IntersectRegions(gfx::NativeRegion r1, + gfx::NativeRegion r2); + + // Returns the union of the two regions. The caller owns the returned object. + static gfx::NativeRegion CombineRegions(gfx::NativeRegion r1, + gfx::NativeRegion r2); + + // Returns the difference of the two regions. The caller owns the returned + // object. + static gfx::NativeRegion SubtractRegion(gfx::NativeRegion r1, + gfx::NativeRegion r2); #endif private: diff --git a/app/gfx/path_gtk.cc b/app/gfx/path_gtk.cc index 9a2b92c..e9aee05 100644 --- a/app/gfx/path_gtk.cc +++ b/app/gfx/path_gtk.cc @@ -11,7 +11,7 @@ namespace gfx { -GdkRegion* Path::CreateGdkRegion() const { +GdkRegion* Path::CreateNativeRegion() const { int point_count = getPoints(NULL, 0); if (point_count <= 1) { // NOTE: ideally this would return gdk_empty_region, but that returns a @@ -31,4 +31,25 @@ GdkRegion* Path::CreateGdkRegion() const { return gdk_region_polygon(gdk_points.get(), point_count, GDK_EVEN_ODD_RULE); } +// static +NativeRegion Path::IntersectRegions(NativeRegion r1, NativeRegion r2) { + GdkRegion* copy = gdk_region_copy(r1); + gdk_region_intersect(copy, r2); + return copy; +} + +// static +NativeRegion Path::CombineRegions(NativeRegion r1, NativeRegion r2) { + GdkRegion* copy = gdk_region_copy(r1); + gdk_region_union(copy, r2); + return copy; +} + +// static +NativeRegion Path::SubtractRegion(NativeRegion r1, NativeRegion r2) { + GdkRegion* copy = gdk_region_copy(r1); + gdk_region_subtract(copy, r2); + return copy; +} + } // namespace gfx diff --git a/app/gfx/path_win.cc b/app/gfx/path_win.cc index 72fce71..5a337bb 100644 --- a/app/gfx/path_win.cc +++ b/app/gfx/path_win.cc @@ -8,7 +8,7 @@ namespace gfx { -HRGN Path::CreateHRGN() const { +HRGN Path::CreateNativeRegion() const { int point_count = getPoints(NULL, 0); scoped_array<SkPoint> points(new SkPoint[point_count]); getPoints(points.get(), point_count); @@ -21,4 +21,25 @@ HRGN Path::CreateHRGN() const { return ::CreatePolygonRgn(windows_points.get(), point_count, ALTERNATE); } +// static +NativeRegion Path::IntersectRegions(NativeRegion r1, NativeRegion r2) { + HRGN dest = CreateRectRgn(0, 0, 1, 1); + CombineRgn(dest, r1, r2, RGN_AND); + return dest; +} + +// static +NativeRegion Path::CombineRegions(NativeRegion r1, NativeRegion r2) { + HRGN dest = CreateRectRgn(0, 0, 1, 1); + CombineRgn(dest, r1, r2, RGN_OR); + return dest; +} + +// static +NativeRegion Path::SubtractRegion(NativeRegion r1, NativeRegion r2) { + HRGN dest = CreateRectRgn(0, 0, 1, 1); + CombineRgn(dest, r1, r2, RGN_DIFF); + return dest; +} + } // namespace gfx diff --git a/app/win_util.h b/app/win_util.h index c9340d1..3140fbe 100644 --- a/app/win_util.h +++ b/app/win_util.h @@ -25,7 +25,6 @@ using ::ScopedHandle; using ::ScopedFindFileHandle; using ::ScopedHDC; using ::ScopedBitmap; -using ::ScopedHRGN; // Simple scoped memory releaser class for COM allocated memory. // Example: |