Chromium Code Reviews| Index: chrome/browser/ui/panels/panel_browser_window_gtk.cc |
| diff --git a/chrome/browser/ui/panels/panel_browser_window_gtk.cc b/chrome/browser/ui/panels/panel_browser_window_gtk.cc |
| index d6461451f22d11be0b80bf688d5f647cd6c9b831..24ce7f9302663aa8162eb8f457ca2ea712df9d4f 100644 |
| --- a/chrome/browser/ui/panels/panel_browser_window_gtk.cc |
| +++ b/chrome/browser/ui/panels/panel_browser_window_gtk.cc |
| @@ -8,6 +8,7 @@ |
| #include "chrome/browser/ui/browser_list.h" |
| #include "chrome/browser/ui/gtk/browser_titlebar.h" |
| #include "chrome/browser/ui/gtk/custom_button.h" |
| +#include "chrome/browser/ui/gtk/theme_service_gtk.h" |
| #include "chrome/browser/ui/panels/panel.h" |
| #include "chrome/browser/ui/panels/panel_bounds_animation.h" |
| #include "chrome/browser/ui/panels/panel_browser_titlebar_gtk.h" |
| @@ -16,27 +17,54 @@ |
| #include "chrome/browser/ui/panels/panel_strip.h" |
| #include "chrome/common/chrome_notification_types.h" |
| #include "content/public/browser/notification_service.h" |
| +#include "grit/theme_resources_standard.h" |
| +#include "third_party/skia/include/core/SkShader.h" |
| +#include "ui/gfx/canvas.h" |
| +#include "ui/gfx/image/cairo_cached_surface.h" |
| +#include "ui/gfx/image/image.h" |
| +#include "ui/gfx/skia_util.h" |
| using content::WebContents; |
| namespace { |
| -// RGB values for titlebar in draw attention state. A shade of orange. |
| -const int kDrawAttentionR = 0xfa; |
| -const int kDrawAttentionG = 0x98; |
| -const int kDrawAttentionB = 0x3a; |
| -const float kDrawAttentionRFraction = kDrawAttentionR / 255.0; |
| -const float kDrawAttentionGFraction = kDrawAttentionG / 255.0; |
| -const float kDrawAttentionBFraction = kDrawAttentionB / 255.0; |
| - |
| -// Markup for title text in draw attention state. Set to color white. |
| -const char* const kDrawAttentionTitleMarkupPrefix = |
| - "<span fgcolor='#ffffff'>"; |
| -const char* const kDrawAttentionTitleMarkupSuffix = "</span>"; |
| +// Colors used to draw titlebar and frame for drawing attention under default |
| +// theme. It is also used in non-default theme since attention color is not |
| +// defined in the theme. |
| +const SkColor kAttentionBackgroundDefaultColorStart = |
| + SkColorSetRGB(0xff, 0xab, 0x57); |
| +const SkColor kAttentionBackgroundDefaultColorEnd = |
| + SkColorSetRGB(0xff, 0xab, 0x57); |
| // Set minimium width for window really small. |
| const int kMinWindowWidth = 26; |
| +gfx::Image* CreateGradientImage(SkColor start_color, SkColor end_color) { |
| + // Though the height of titlebar, used for creating gradient, cannot be |
| + // pre-determined, we use a reasonably bigger value that is obtained from |
| + // the experimentation and should work for most cases. |
| + const int gradient_size = 32; |
| + SkShader* shader = gfx::CreateGradientShader( |
| + 0, gradient_size, start_color, end_color); |
| + SkPaint paint; |
| + paint.setStyle(SkPaint::kFill_Style); |
| + paint.setAntiAlias(true); |
| + paint.setShader(shader); |
| + shader->unref(); |
| + gfx::Canvas canvas(gfx::Size(1, gradient_size), true); |
| + canvas.DrawRect(gfx::Rect(0, 0, 1, gradient_size), paint); |
| + return new gfx::Image(canvas.ExtractBitmap()); |
| +} |
| + |
| +gfx::Image* GetAttentionBackgroundDefaultImage() { |
| + static gfx::Image* image = NULL; |
| + if (!image) { |
| + image = CreateGradientImage(kAttentionBackgroundDefaultColorStart, |
| + kAttentionBackgroundDefaultColorEnd); |
| + } |
| + return image; |
| +} |
| + |
| } // namespace |
| NativePanel* Panel::CreateNativePanel(Browser* browser, Panel* panel, |
| @@ -84,10 +112,24 @@ void PanelBrowserWindowGtk::Init() { |
| content::Source<GtkWindow>(window())); |
| } |
| +bool PanelBrowserWindowGtk::ShouldDrawContentDropShadow() const { |
| + return !panel_->IsMinimized(); |
| +} |
| + |
| BrowserTitlebar* PanelBrowserWindowGtk::CreateBrowserTitlebar() { |
| return new PanelBrowserTitlebarGtk(this, window()); |
| } |
| +PanelBrowserTitlebarGtk* PanelBrowserWindowGtk::GetPanelTitlebar() const { |
| + return static_cast<PanelBrowserTitlebarGtk*>(titlebar()); |
| +} |
| + |
| +PanelBrowserWindowGtk::PaintState PanelBrowserWindowGtk::GetPaintState() const { |
| + if (is_drawing_attention_) |
| + return PAINT_FOR_ATTENTION; |
| + return IsActive() ? PAINT_AS_ACTIVE : PAINT_AS_INACTIVE; |
| +} |
| + |
| bool PanelBrowserWindowGtk::GetWindowEdge(int x, int y, GdkWindowEdge* edge) { |
| // Only detect the window edge when panels can be resized by the user. |
| // This method is used by the base class to detect when the cursor has |
| @@ -196,51 +238,53 @@ void PanelBrowserWindowGtk::OnSizeChanged(int width, int height) { |
| content::NotificationService::NoDetails()); |
| } |
| -bool PanelBrowserWindowGtk::UseCustomFrame() { |
| +bool PanelBrowserWindowGtk::UseCustomFrame() const { |
| // We always use custom frame for panels. |
| - return TRUE; |
| + return true; |
| +} |
| + |
| +bool PanelBrowserWindowGtk::UsingCustomPopupFrame() const { |
| + // We do not draw custom popup frame. |
| + return false; |
| } |
| void PanelBrowserWindowGtk::DrawPopupFrame(cairo_t* cr, |
| GtkWidget* widget, |
| GdkEventExpose* event) { |
| - static_cast<PanelBrowserTitlebarGtk*>(titlebar())-> |
| - UpdateMinimizeRestoreButtonVisibility(); |
| - |
| - BrowserWindowGtk::DrawPopupFrame(cr, widget, event); |
| + NOTREACHED(); |
| +} |
| + |
| +const gfx::Image* PanelBrowserWindowGtk::GetThemeFrameImage() const { |
| + PaintState paint_state = GetPaintState(); |
| + if (paint_state == PAINT_FOR_ATTENTION) |
| + return GetAttentionBackgroundDefaultImage(); |
|
Evan Stade
2012/04/30 23:07:21
this function appears to be used regardless of whe
|
| + |
| + ThemeServiceGtk* theme_provider = ThemeServiceGtk::GetFrom( |
| + browser()->profile()); |
| + if (theme_provider->UsingDefaultTheme()) { |
| + // We choose to use the window frame theme to paint panels for the default |
| + // theme. This is because the default tab theme does not work well for the |
| + // user to recognize active and inactive panels. |
| + return theme_provider->GetImageNamed((paint_state == PAINT_AS_ACTIVE) ? |
|
Evan Stade
2012/04/30 23:07:21
get rid of unnecessary parens
|
| + IDR_THEME_FRAME : IDR_THEME_FRAME_INACTIVE); |
| + } |
| - if (is_drawing_attention_) |
| - DrawAttentionFrame(cr, widget, event); |
| + return theme_provider->GetImageNamed((paint_state == PAINT_AS_ACTIVE) ? |
|
Evan Stade
2012/04/30 23:07:21
ditto
|
| + IDR_THEME_TOOLBAR : IDR_THEME_TAB_BACKGROUND); |
| } |
| void PanelBrowserWindowGtk::DrawCustomFrame(cairo_t* cr, |
| GtkWidget* widget, |
| GdkEventExpose* event) { |
| - static_cast<PanelBrowserTitlebarGtk*>(titlebar())-> |
| - UpdateMinimizeRestoreButtonVisibility(); |
| - |
| - BrowserWindowGtk::DrawCustomFrame(cr, widget, event); |
| + GetPanelTitlebar()->UpdateMinimizeRestoreButtonVisibility(); |
| - if (is_drawing_attention_) |
| - DrawAttentionFrame(cr, widget, event); |
| -} |
| - |
| -void PanelBrowserWindowGtk::DrawAttentionFrame(cairo_t* cr, |
| - GtkWidget* widget, |
| - GdkEventExpose* event) { |
| - cairo_set_source_rgb(cr, kDrawAttentionRFraction, |
| - kDrawAttentionGFraction, |
| - kDrawAttentionBFraction); |
| - |
| - GdkRectangle dest_rectangle = GetTitlebarRectForDrawAttention(); |
| - GdkRegion* dest_region = gdk_region_rectangle(&dest_rectangle); |
| - |
| - gdk_region_intersect(dest_region, event->region); |
| - gdk_cairo_region(cr, dest_region); |
| + gfx::CairoCachedSurface* surface = GetThemeFrameImage()->ToCairo(); |
| - cairo_clip(cr); |
| - cairo_paint(cr); |
| - gdk_region_destroy(dest_region); |
| + surface->SetSource(cr, widget, 0, 0); |
| + cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REPEAT); |
| + cairo_rectangle(cr, event->area.x, event->area.y, |
| + event->area.width, event->area.height); |
| + cairo_fill(cr); |
| } |
| void PanelBrowserWindowGtk::ActiveWindowChanged(GdkWindow* active_window) { |
| @@ -253,27 +297,6 @@ void PanelBrowserWindowGtk::ActiveWindowChanged(GdkWindow* active_window) { |
| panel_->OnActiveStateChanged(is_active); |
| } |
| -BrowserWindowGtk::TitleDecoration PanelBrowserWindowGtk::GetWindowTitle( |
| - std::string* title) const { |
| - if (is_drawing_attention_) { |
| - std::string title_original; |
| - BrowserWindowGtk::TitleDecoration title_decoration = |
| - BrowserWindowGtk::GetWindowTitle(&title_original); |
| - DCHECK_EQ(BrowserWindowGtk::PLAIN_TEXT, title_decoration); |
| - gchar* title_escaped = g_markup_escape_text(title_original.c_str(), -1); |
| - gchar* title_with_markup = g_strconcat(kDrawAttentionTitleMarkupPrefix, |
| - title_escaped, |
| - kDrawAttentionTitleMarkupSuffix, |
| - NULL); |
| - *title = title_with_markup; |
| - g_free(title_escaped); |
| - g_free(title_with_markup); |
| - return BrowserWindowGtk::PANGO_MARKUP; |
| - } else { |
| - return BrowserWindowGtk::GetWindowTitle(title); |
| - } |
| -} |
| - |
| void PanelBrowserWindowGtk::Observe( |
| int type, |
| const content::NotificationSource& source, |
| @@ -411,11 +434,8 @@ void PanelBrowserWindowGtk::DrawAttention(bool draw_attention) { |
| is_drawing_attention_ = draw_attention; |
| - GdkRectangle rect = GetTitlebarRectForDrawAttention(); |
| - gdk_window_invalidate_rect( |
| - gtk_widget_get_window(GTK_WIDGET(window())), &rect, TRUE); |
| - |
| - UpdateTitleBar(); |
| + GetPanelTitlebar()->UpdateTextColor(); |
| + InvalidateWindow(); |
| if ((panel_->attention_mode() & Panel::USE_SYSTEM_ATTENTION) != 0) |
| ::BrowserWindowGtk::FlashFrame(draw_attention); |
| @@ -449,12 +469,6 @@ void PanelBrowserWindowGtk::DestroyPanelBrowser() { |
| DestroyBrowser(); |
| } |
| -gfx::Size PanelBrowserWindowGtk::IconOnlySize() const { |
| - GtkAllocation allocation; |
| - gtk_widget_get_allocation(titlebar_widget(), &allocation); |
| - return gfx::Size(titlebar()->IconOnlyWidth(), allocation.height); |
| -} |
| - |
| void PanelBrowserWindowGtk::EnsurePanelFullyVisible() { |
| gtk_window_present(window()); |
| } |
| @@ -505,7 +519,7 @@ bool PanelBrowserWindowGtk::IsAnimatingBounds() const { |
| } |
| void PanelBrowserWindowGtk::AnimationEnded(const ui::Animation* animation) { |
| - titlebar()->SendEnterNotifyToCloseButtonIfUnderMouse(); |
| + GetPanelTitlebar()->SendEnterNotifyToCloseButtonIfUnderMouse(); |
| panel_->manager()->OnPanelAnimationEnded(panel_.get()); |
| } |
| @@ -523,24 +537,6 @@ void PanelBrowserWindowGtk::AnimationProgressed( |
| last_animation_progressed_bounds_ = new_bounds; |
| } |
| -GdkRectangle PanelBrowserWindowGtk::GetTitlebarRectForDrawAttention() const { |
| - GdkRectangle rect; |
| - rect.x = 0; |
| - rect.y = 0; |
| - // We get the window width and not the titlebar_widget() width because we'd |
| - // like for the window borders on either side of the title bar to be the same |
| - // color. |
| - GtkAllocation window_allocation; |
| - gtk_widget_get_allocation(GTK_WIDGET(window()), &window_allocation); |
| - rect.width = window_allocation.width; |
| - |
| - GtkAllocation titlebar_allocation; |
| - gtk_widget_get_allocation(titlebar_widget(), &titlebar_allocation); |
| - rect.height = titlebar_allocation.height; |
| - |
| - return rect; |
| -} |
| - |
| gboolean PanelBrowserWindowGtk::OnTitlebarButtonReleaseEvent( |
| GtkWidget* widget, GdkEventButton* event) { |
| if (event->button != 1) |
| @@ -650,11 +646,7 @@ void NativePanelTestingGtk::FinishDragTitlebar() { |
| } |
| bool NativePanelTestingGtk::VerifyDrawingAttention() const { |
| - std::string title; |
| - BrowserWindowGtk::TitleDecoration decoration = |
| - panel_browser_window_gtk_->GetWindowTitle(&title); |
| - return panel_browser_window_gtk_->IsDrawingAttention() && |
| - decoration == BrowserWindowGtk::PANGO_MARKUP; |
| + return panel_browser_window_gtk_->IsDrawingAttention(); |
| } |
| bool NativePanelTestingGtk::VerifyActiveState(bool is_active) { |
| @@ -679,8 +671,8 @@ bool NativePanelTestingGtk::IsAnimatingBounds() const { |
| bool NativePanelTestingGtk::IsButtonVisible( |
| TitlebarButtonType button_type) const { |
| - PanelBrowserTitlebarGtk* titlebar = static_cast<PanelBrowserTitlebarGtk*>( |
| - panel_browser_window_gtk_->titlebar()); |
| + PanelBrowserTitlebarGtk* titlebar = |
| + panel_browser_window_gtk_->GetPanelTitlebar(); |
| CustomDrawButton* button; |
| switch (button_type) { |
| case CLOSE_BUTTON: |