| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 #ifndef CHROME_BROWSER_GTK_NINE_BOX_H_ | 5 #ifndef CHROME_BROWSER_GTK_NINE_BOX_H_ |
| 6 #define CHROME_BROWSER_GTK_NINE_BOX_H_ | 6 #define CHROME_BROWSER_GTK_NINE_BOX_H_ |
| 7 | 7 |
| 8 #include <gtk/gtk.h> | 8 #include <gtk/gtk.h> |
| 9 | 9 |
| 10 #include "chrome/common/notification_observer.h" | |
| 11 #include "chrome/common/notification_registrar.h" | |
| 12 #include "chrome/common/notification_type.h" | |
| 13 | |
| 14 class ThemeProvider; | |
| 15 | |
| 16 // A NineBox manages a set of source images representing a 3x3 grid, where | 10 // A NineBox manages a set of source images representing a 3x3 grid, where |
| 17 // non-corner images can be tiled to make a larger image. It's used to | 11 // non-corner images can be tiled to make a larger image. It's used to |
| 18 // use bitmaps for constructing image-based resizable widgets like buttons. | 12 // use bitmaps for constructing image-based resizable widgets like buttons. |
| 19 // | 13 // |
| 20 // If you want just a vertical image that stretches in height but is fixed | 14 // If you want just a vertical image that stretches in height but is fixed |
| 21 // in width, only pass in images for the left column (leave others NULL). | 15 // in width, only pass in images for the left column (leave others NULL). |
| 22 // Similarly, for a horizontal image that stretches in width but is fixed in | 16 // Similarly, for a horizontal image that stretches in width but is fixed in |
| 23 // height, only pass in images for the top row. | 17 // height, only pass in images for the top row. |
| 24 // | 18 // |
| 25 // TODO(port): add support for caching server-side pixmaps of prerendered | 19 // TODO(port): add support for caching server-side pixmaps of prerendered |
| 26 // nineboxes. | 20 // nineboxes. |
| 27 class NineBox : public NotificationObserver { | 21 class NineBox { |
| 28 public: | 22 public: |
| 29 // Construct a NineBox with nine images. Images are specified using resource | 23 // Construct a NineBox with nine images. Images are specified using resource |
| 30 // ids that will be passed to the resource bundle. Use 0 for no image. | 24 // ids that will be passed to the resource bundle. Use 0 for no image. |
| 31 NineBox(int top_left, int top, int top_right, int left, int center, int right, | 25 NineBox(int top_left, int top, int top_right, int left, int center, int right, |
| 32 int bottom_left, int bottom, int bottom_right); | 26 int bottom_left, int bottom, int bottom_right); |
| 33 | |
| 34 // Same as above, but use themed images. | |
| 35 NineBox(ThemeProvider* theme_provider, | |
| 36 int top_left, int top, int top_right, int left, int center, int right, | |
| 37 int bottom_left, int bottom, int bottom_right); | |
| 38 | |
| 39 ~NineBox(); | 27 ~NineBox(); |
| 40 | 28 |
| 41 // Render the NineBox to |dst|. | 29 // Render the NineBox to |dst|. |
| 42 // The images will be tiled to fit into the widget. | 30 // The images will be tiled to fit into the widget. |
| 43 void RenderToWidget(GtkWidget* dst) const; | 31 void RenderToWidget(GtkWidget* dst) const; |
| 44 | 32 |
| 45 // Render the top row of images to |dst| between |x1| and |x1| + |width|. | 33 // Render the top row of images to |dst| between |x1| and |x1| + |width|. |
| 46 // This is split from RenderToWidget so the toolbar can use it. | 34 // This is split from RenderToWidget so the toolbar can use it. |
| 47 void RenderTopCenterStrip(cairo_t* cr, int x, int y, int width) const; | 35 void RenderTopCenterStrip(cairo_t* cr, int x, int y, int width) const; |
| 48 | 36 |
| 49 // Change all pixels that are white in |images_| to have 0 opacity. | 37 // Change all pixels that are white in |images_| to have 0 opacity. |
| 50 void ChangeWhiteToTransparent(); | 38 void ChangeWhiteToTransparent(); |
| 51 | 39 |
| 52 // Set the shape of |widget| to match that of the ninebox. Note that |widget| | 40 // Set the shape of |widget| to match that of the ninebox. Note that |widget| |
| 53 // must have its own window and be allocated. Also, currently only the top | 41 // must have its own window and be allocated. Also, currently only the top |
| 54 // three images are used. | 42 // three images are used. |
| 55 // TODO(estade): extend this function to use all 9 images (if it's ever | 43 // TODO(estade): extend this function to use all 9 images (if it's ever |
| 56 // needed). | 44 // needed). |
| 57 void ContourWidget(GtkWidget* widget) const; | 45 void ContourWidget(GtkWidget* widget) const; |
| 58 | 46 |
| 59 // Provide NotificationObserver implementation. | |
| 60 virtual void Observe(NotificationType type, | |
| 61 const NotificationSource& source, | |
| 62 const NotificationDetails& details); | |
| 63 private: | 47 private: |
| 64 GdkPixbuf* images_[9]; | 48 GdkPixbuf* images_[9]; |
| 65 | |
| 66 // We need to remember the image ids that the user passes in and the theme | |
| 67 // provider so we can reload images if the user changes theme. | |
| 68 int image_ids_[9]; | |
| 69 ThemeProvider* theme_provider_; | |
| 70 | |
| 71 // Used to listen for theme change notifications. | |
| 72 NotificationRegistrar registrar_; | |
| 73 }; | 49 }; |
| 74 | 50 |
| 75 #endif // CHROME_BROWSER_GTK_NINE_BOX_H_ | 51 #endif // CHROME_BROWSER_GTK_NINE_BOX_H_ |
| OLD | NEW |