| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "chrome/browser/ui/gtk/infobars/infobar_container_gtk.h" | 5 #include "chrome/browser/ui/gtk/infobars/infobar_container_gtk.h" |
| 6 | 6 |
| 7 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/message_loop/message_loop.h" | |
| 12 #include "chrome/browser/infobars/infobar_delegate.h" | 11 #include "chrome/browser/infobars/infobar_delegate.h" |
| 13 #include "chrome/browser/platform_util.h" | 12 #include "chrome/browser/platform_util.h" |
| 14 #include "chrome/browser/ui/browser_window.h" | 13 #include "chrome/browser/ui/browser_window.h" |
| 15 #include "chrome/browser/ui/gtk/browser_window_gtk.h" | 14 #include "chrome/browser/ui/gtk/browser_window_gtk.h" |
| 16 #include "chrome/browser/ui/gtk/gtk_util.h" | 15 #include "chrome/browser/ui/gtk/gtk_util.h" |
| 17 #include "chrome/browser/ui/gtk/infobars/infobar_gtk.h" | 16 #include "chrome/browser/ui/gtk/infobars/infobar_gtk.h" |
| 18 #include "third_party/skia/include/effects/SkGradientShader.h" | 17 #include "third_party/skia/include/effects/SkGradientShader.h" |
| 19 #include "ui/gfx/canvas_skia_paint.h" | 18 #include "ui/gfx/canvas_skia_paint.h" |
| 20 #include "ui/gfx/color_utils.h" | 19 #include "ui/gfx/color_utils.h" |
| 21 #include "ui/gfx/gtk_compat.h" | 20 #include "ui/gfx/gtk_compat.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 46 return sum; | 45 return sum; |
| 47 } | 46 } |
| 48 | 47 |
| 49 bool InfoBarContainerGtk::ContainsInfobars() const { | 48 bool InfoBarContainerGtk::ContainsInfobars() const { |
| 50 return !infobars_gtk_.empty(); | 49 return !infobars_gtk_.empty(); |
| 51 } | 50 } |
| 52 | 51 |
| 53 void InfoBarContainerGtk::PlatformSpecificAddInfoBar(InfoBar* infobar, | 52 void InfoBarContainerGtk::PlatformSpecificAddInfoBar(InfoBar* infobar, |
| 54 size_t position) { | 53 size_t position) { |
| 55 InfoBarGtk* infobar_gtk = static_cast<InfoBarGtk*>(infobar); | 54 InfoBarGtk* infobar_gtk = static_cast<InfoBarGtk*>(infobar); |
| 56 infobar_gtk->InitWidgets(); | |
| 57 infobars_gtk_.insert(infobars_gtk_.begin() + position, infobar_gtk); | 55 infobars_gtk_.insert(infobars_gtk_.begin() + position, infobar_gtk); |
| 58 | 56 |
| 59 if (infobars_gtk_.back() == infobar_gtk) { | 57 if (infobars_gtk_.back() == infobar_gtk) { |
| 60 gtk_box_pack_start(GTK_BOX(widget()), infobar_gtk->widget(), | 58 gtk_box_pack_start(GTK_BOX(widget()), infobar_gtk->widget(), |
| 61 FALSE, FALSE, 0); | 59 FALSE, FALSE, 0); |
| 62 } else { | 60 } else { |
| 63 // Clear out our container and then repack it to make sure everything is in | 61 // Clear out our container and then repack it to make sure everything is in |
| 64 // the right order. | 62 // the right order. |
| 65 gtk_util::RemoveAllChildren(widget()); | 63 gtk_util::RemoveAllChildren(widget()); |
| 66 | 64 |
| 67 // Repack our container. | 65 // Repack our container. |
| 68 for (std::vector<InfoBarGtk*>::const_iterator it = infobars_gtk_.begin(); | 66 for (std::vector<InfoBarGtk*>::const_iterator it = infobars_gtk_.begin(); |
| 69 it != infobars_gtk_.end(); ++it) { | 67 it != infobars_gtk_.end(); ++it) { |
| 70 gtk_box_pack_start(GTK_BOX(widget()), (*it)->widget(), | 68 gtk_box_pack_start(GTK_BOX(widget()), (*it)->widget(), |
| 71 FALSE, FALSE, 0); | 69 FALSE, FALSE, 0); |
| 72 } | 70 } |
| 73 } | 71 } |
| 74 } | 72 } |
| 75 | 73 |
| 76 void InfoBarContainerGtk::PlatformSpecificRemoveInfoBar(InfoBar* infobar) { | 74 void InfoBarContainerGtk::PlatformSpecificRemoveInfoBar(InfoBar* infobar) { |
| 77 InfoBarGtk* infobar_gtk = static_cast<InfoBarGtk*>(infobar); | 75 InfoBarGtk* infobar_gtk = static_cast<InfoBarGtk*>(infobar); |
| 78 gtk_container_remove(GTK_CONTAINER(widget()), infobar_gtk->widget()); | 76 gtk_container_remove(GTK_CONTAINER(widget()), infobar_gtk->widget()); |
| 79 | 77 |
| 80 std::vector<InfoBarGtk*>::iterator it = | 78 std::vector<InfoBarGtk*>::iterator it = |
| 81 std::find(infobars_gtk_.begin(), infobars_gtk_.end(), infobar); | 79 std::find(infobars_gtk_.begin(), infobars_gtk_.end(), infobar); |
| 82 if (it != infobars_gtk_.end()) | 80 if (it != infobars_gtk_.end()) |
| 83 infobars_gtk_.erase(it); | 81 infobars_gtk_.erase(it); |
| 84 | |
| 85 base::MessageLoop::current()->DeleteSoon(FROM_HERE, infobar); | |
| 86 } | 82 } |
| 87 | 83 |
| 88 void InfoBarContainerGtk::PlatformSpecificInfoBarStateChanged( | 84 void InfoBarContainerGtk::PlatformSpecificInfoBarStateChanged( |
| 89 bool is_animating) { | 85 bool is_animating) { |
| 90 // Force a redraw of all infobars since something has a new height and we | 86 // Force a redraw of all infobars since something has a new height and we |
| 91 // need to make sure we animate our arrows. | 87 // need to make sure we animate our arrows. |
| 92 for (std::vector<InfoBarGtk*>::iterator it = infobars_gtk_.begin(); | 88 for (std::vector<InfoBarGtk*>::iterator it = infobars_gtk_.begin(); |
| 93 it != infobars_gtk_.end(); ++it) { | 89 it != infobars_gtk_.end(); ++it) { |
| 94 gtk_widget_queue_draw((*it)->widget()); | 90 gtk_widget_queue_draw((*it)->widget()); |
| 95 } | 91 } |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 SkCanvas& canvas = *canvas_paint.sk_canvas(); | 183 SkCanvas& canvas = *canvas_paint.sk_canvas(); |
| 188 | 184 |
| 189 canvas.drawPath(path, paint); | 185 canvas.drawPath(path, paint); |
| 190 | 186 |
| 191 paint.setShader(NULL); | 187 paint.setShader(NULL); |
| 192 paint.setColor(SkColorSetA(gfx::GdkColorToSkColor(source->GetBorderColor()), | 188 paint.setColor(SkColorSetA(gfx::GdkColorToSkColor(source->GetBorderColor()), |
| 193 SkColorGetA(grad_colors[0]))); | 189 SkColorGetA(grad_colors[0]))); |
| 194 paint.setStyle(SkPaint::kStroke_Style); | 190 paint.setStyle(SkPaint::kStroke_Style); |
| 195 canvas.drawPath(path, paint); | 191 canvas.drawPath(path, paint); |
| 196 } | 192 } |
| OLD | NEW |