summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordeanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-11 18:05:07 +0000
committerdeanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-11 18:05:07 +0000
commit9bae4b9a123cda92bc3bd0da16784d9ec75d1494 (patch)
tree3b45d3f8c1be8d4647cec0840e33e1081d4cd3bd
parente232e00e73a93453328cf8634001df93860d8d1e (diff)
downloadchromium_src-9bae4b9a123cda92bc3bd0da16784d9ec75d1494.zip
chromium_src-9bae4b9a123cda92bc3bd0da16784d9ec75d1494.tar.gz
chromium_src-9bae4b9a123cda92bc3bd0da16784d9ec75d1494.tar.bz2
Add a gtk_utils (like gdi_utils), with region rectangle subtraction.
This will be used like the gdi functions, for constructing clipping regions. Add ToGdkRectangle() on gfx::Rect, similar to the win32 and CG methods. Make the scons file better reflect which files are platform specific. Review URL: http://codereview.chromium.org/20259 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@9574 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--base/gfx/base_gfx.scons18
-rwxr-xr-xbase/gfx/gtk_util.cc24
-rwxr-xr-xbase/gfx/gtk_util.h22
-rwxr-xr-x[-rw-r--r--]base/gfx/rect.cc5
-rwxr-xr-x[-rw-r--r--]base/gfx/rect.h2
5 files changed, 59 insertions, 12 deletions
diff --git a/base/gfx/base_gfx.scons b/base/gfx/base_gfx.scons
index 4c93190..b5356ec 100644
--- a/base/gfx/base_gfx.scons
+++ b/base/gfx/base_gfx.scons
@@ -28,10 +28,6 @@ if env.Bit('windows'):
input_files = ChromeFileList([
'jpeg_codec.cc',
'jpeg_codec.h',
- 'gdi_util.cc',
- 'gdi_util.h',
- 'native_theme.cc',
- 'native_theme.h',
'png_decoder.cc',
'png_decoder.h',
'png_encoder.cc',
@@ -44,19 +40,17 @@ input_files = ChromeFileList([
'size.h',
])
-if env.Bit('posix'):
- # Remove files that still need to be ported from the input_files list.
- # TODO(port): delete files from this list as they get ported.
- input_files.Remove(
- 'gdi_util.cc',
- 'native_theme.cc',
- )
-
if env.Bit('windows'):
input_files.Extend([
+ 'native_theme.cc',
+ 'native_theme.h',
+ 'gdi_util.cc',
+ 'gdi_util.h',
])
elif env.Bit('linux'):
input_files.Extend([
+ 'gtk_util.cc',
+ 'gtk_util.h',
])
env.ChromeLibrary('base_gfx', input_files)
diff --git a/base/gfx/gtk_util.cc b/base/gfx/gtk_util.cc
new file mode 100755
index 0000000..26601ca
--- /dev/null
+++ b/base/gfx/gtk_util.cc
@@ -0,0 +1,24 @@
+// 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 "base/gfx/gtk_util.h"
+
+#include <gdk/gdk.h>
+
+#include "base/gfx/rect.h"
+
+namespace gfx {
+
+void SubtractRectanglesFromRegion(GdkRegion* region,
+ const std::vector<gfx::Rect>& cutouts) {
+ for (size_t i = 0; i < cutouts.size(); ++i) {
+ GdkRectangle rect = cutouts[i].ToGdkRectangle();
+ GdkRegion* rect_region = gdk_region_rectangle(&rect);
+ gdk_region_subtract(region, rect_region);
+ // TODO(deanm): It would be nice to be able to reuse the GdkRegion here.
+ gdk_region_destroy(rect_region);
+ }
+}
+
+} // namespace gfx
diff --git a/base/gfx/gtk_util.h b/base/gfx/gtk_util.h
new file mode 100755
index 0000000..7062d59
--- /dev/null
+++ b/base/gfx/gtk_util.h
@@ -0,0 +1,22 @@
+// 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 BASE_GFX_GTK_UTIL_H_
+#define BASE_GFX_GTK_UTIL_H_
+
+#include <vector>
+
+typedef struct _GdkRegion GdkRegion;
+
+namespace gfx {
+
+class Rect;
+
+// Modify the given region by subtracting the given rectangles.
+void SubtractRectanglesFromRegion(GdkRegion* region,
+ const std::vector<gfx::Rect>& cutouts);
+
+} // namespace gfx
+
+#endif // BASE_GFX_GTK_UTIL_H_
diff --git a/base/gfx/rect.cc b/base/gfx/rect.cc
index 64d68db..3e7d782 100644..100755
--- a/base/gfx/rect.cc
+++ b/base/gfx/rect.cc
@@ -140,6 +140,11 @@ RECT Rect::ToRECT() const {
r.bottom = bottom();
return r;
}
+#elif defined(OS_LINUX)
+GdkRectangle Rect::ToGdkRectangle() const {
+ GdkRectangle r = {x(), y(), width(), height()};
+ return r;
+}
#elif defined(OS_MACOSX)
CGRect Rect::ToCGRect() const {
return CGRectMake(x(), y(), width(), height());
diff --git a/base/gfx/rect.h b/base/gfx/rect.h
index 362cd31..54e864d 100644..100755
--- a/base/gfx/rect.h
+++ b/base/gfx/rect.h
@@ -97,6 +97,8 @@ class Rect {
#if defined(OS_WIN)
// Construct an equivalent Win32 RECT object.
RECT ToRECT() const;
+#elif defined(OS_LINUX)
+ GdkRectangle ToGdkRectangle() const;
#elif defined(OS_MACOSX)
// Construct an equivalent CoreGraphics object.
CGRect ToCGRect() const;