Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(497)

Side by Side Diff: chrome/browser/gtk/blocked_popup_container_view_gtk.cc

Issue 118480: GTK: Implement BlockedPopupContainerView for linux. (Closed)
Patch Set: Fix for the CreateBorderBin case. Created 11 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this
2 // source code is governed by a BSD-style license that can be found in the
3 // LICENSE file.
4
5 #include "chrome/browser/gtk/blocked_popup_container_view_gtk.h"
6
7 #include "app/l10n_util.h"
8 #include "base/gfx/gtk_util.h"
9 #include "base/string_util.h"
10 #include "chrome/browser/gtk/custom_button.h"
11 #include "chrome/browser/gtk/gtk_chrome_button.h"
12 #include "chrome/browser/profile.h"
13 #include "chrome/browser/tab_contents/tab_contents.h"
14 #include "chrome/browser/tab_contents/tab_contents_view_gtk.h"
15 #include "chrome/common/gtk_util.h"
16 #include "grit/generated_resources.h"
17 #include "grit/theme_resources.h"
18
19 namespace {
20
21 // Inner padding between the border and the text label.
22 const int kInternalTopBottomPadding = 1;
23 const int kInternalLeftRightPadding = 2;
24
25 // Size of the border painted in kBorderColor
26 const int kBorderPadding = 1;
27
28 // Color of the border.
29 const GdkColor kFrameBorderColor = GDK_COLOR_RGB(190, 205, 223);
30
31 // TODO(erg): The windows signal has a gradient on the background. I don't know
32 // how to do that so we just fill with the bottom color.
33 const GdkColor kBackgroundColorBottom = GDK_COLOR_RGB(219, 235, 255);
34
35 } // namespace
36
37 // static
38 BlockedPopupContainerView* BlockedPopupContainerView::Create(
39 BlockedPopupContainer* container) {
40 return new BlockedPopupContainerViewGtk(container);
41 }
42
43 BlockedPopupContainerViewGtk::~BlockedPopupContainerViewGtk() {
44 container_.Destroy();
45 }
46
47 TabContentsViewGtk* BlockedPopupContainerViewGtk::ContainingView() {
48 return static_cast<TabContentsViewGtk*>(
49 model_->GetConstrainingContents(NULL)->view());
50 }
51
52 void BlockedPopupContainerViewGtk::GetURLAndTitleForPopup(
53 size_t index, string16* url, string16* title) const {
54 DCHECK(url);
55 DCHECK(title);
56 TabContents* tab_contents = model_->GetTabContentsAt(index);
57 const GURL& tab_contents_url = tab_contents->GetURL().GetOrigin();
58 *url = UTF8ToUTF16(tab_contents_url.possibly_invalid_spec());
59 *title = tab_contents->GetTitle();
60 }
61
62 // Overridden from BlockedPopupContainerView:
63 void BlockedPopupContainerViewGtk::SetPosition() {
64 // No-op. Not required with the GTK version.
65 }
66
67 void BlockedPopupContainerViewGtk::ShowView() {
68 // TODO(erg): Animate in.
69 gtk_widget_show_all(container_.get());
70 }
71
72 void BlockedPopupContainerViewGtk::UpdateLabel() {
73 size_t blocked_popups = model_->GetBlockedPopupCount();
74
75 gtk_button_set_label(
76 GTK_BUTTON(menu_button_),
77 (blocked_popups > 0) ?
78 l10n_util::GetStringFUTF8(IDS_POPUPS_BLOCKED_COUNT,
79 UintToString16(blocked_popups)).c_str() :
80 l10n_util::GetStringUTF8(IDS_POPUPS_UNBLOCKED).c_str());
81 }
82
83 void BlockedPopupContainerViewGtk::HideView() {
84 // TODO(erg): Animate out.
85 gtk_widget_hide(container_.get());
86 }
87
88 void BlockedPopupContainerViewGtk::Destroy() {
89 ContainingView()->RemoveBlockedPopupView(this);
90 delete this;
91 }
92
93 bool BlockedPopupContainerViewGtk::IsCommandEnabled(int command_id) const {
94 return true;
95 }
96
97 bool BlockedPopupContainerViewGtk::IsItemChecked(int id) const {
98 DCHECK_GT(id, 0);
99 size_t id_size_t = static_cast<size_t>(id);
100 if (id_size_t > BlockedPopupContainer::kImpossibleNumberOfPopups) {
101 return model_->IsHostWhitelisted(
102 id_size_t - BlockedPopupContainer::kImpossibleNumberOfPopups - 1);
103 }
104
105 return false;
106 }
107
108 void BlockedPopupContainerViewGtk::ExecuteCommand(int id) {
109 DCHECK_GT(id, 0);
110 size_t id_size_t = static_cast<size_t>(id);
111 if (id_size_t > BlockedPopupContainer::kImpossibleNumberOfPopups) {
112 // Decrement id since all index based commands have 1 added to them. (See
113 // ButtonPressed() for detail).
114 model_->ToggleWhitelistingForHost(
115 id_size_t - BlockedPopupContainer::kImpossibleNumberOfPopups - 1);
116 } else {
117 model_->LaunchPopupAtIndex(id_size_t - 1);
118 }
119 }
120
121 BlockedPopupContainerViewGtk::BlockedPopupContainerViewGtk(
122 BlockedPopupContainer* container)
123 : model_(container),
124 close_button_(CustomDrawButton::CloseButton()) {
125 Init();
126 }
127
128 void BlockedPopupContainerViewGtk::Init() {
129 menu_button_ = gtk_chrome_button_new();
130 UpdateLabel();
131 g_signal_connect(menu_button_, "clicked",
132 G_CALLBACK(OnMenuButtonClicked), this);
133
134 GtkWidget* hbox = gtk_hbox_new(FALSE, 0);
135 gtk_box_pack_start(GTK_BOX(hbox), menu_button_, FALSE, FALSE, 0);
136 gtk_util::CenterWidgetInHBox(hbox, close_button_->widget(), true, 0);
137 g_signal_connect(close_button_->widget(), "clicked",
138 G_CALLBACK(OnCloseButtonClicked), this);
139
140 GtkWidget* padding = gtk_util::CreateGtkBorderBin(
141 hbox, &kBackgroundColorBottom,
142 kInternalTopBottomPadding, kInternalTopBottomPadding,
143 kInternalLeftRightPadding, kInternalLeftRightPadding);
144
145 container_.Own(gtk_util::CreateGtkBorderBin(padding, &kFrameBorderColor,
146 kBorderPadding, kBorderPadding, kBorderPadding, kBorderPadding));
147
148 ContainingView()->AttachBlockedPopupView(this);
149 }
150
151 void BlockedPopupContainerViewGtk::OnMenuButtonClicked(
152 GtkButton *button, BlockedPopupContainerViewGtk* container) {
153 container->launch_menu_.reset(new MenuGtk(container, false));
154
155 // Set items 1 .. popup_count as individual popups.
156 size_t popup_count = container->model_->GetBlockedPopupCount();
157 for (size_t i = 0; i < popup_count; ++i) {
158 string16 url, title;
159 container->GetURLAndTitleForPopup(i, &url, &title);
160 // We can't just use the index into container_ here because Menu reserves
161 // the value 0 as the nop command.
162 container->launch_menu_->AppendMenuItemWithLabel(i + 1,
163 l10n_util::GetStringFUTF8(IDS_POPUP_TITLE_FORMAT, url, title));
164 }
165
166 // Set items (kImpossibleNumberOfPopups + 1) ..
167 // (kImpossibleNumberOfPopups + 1 + hosts.size()) as hosts.
168 std::vector<std::string> hosts(container->model_->GetHosts());
169 if (!hosts.empty() && (popup_count > 0))
170 container->launch_menu_->AppendSeparator();
171 for (size_t i = 0; i < hosts.size(); ++i) {
172 container->launch_menu_->AppendCheckMenuItemWithLabel(
173 BlockedPopupContainer::kImpossibleNumberOfPopups + i + 1,
174 l10n_util::GetStringFUTF8(IDS_POPUP_HOST_FORMAT,
175 UTF8ToUTF16(hosts[i])));
176 }
177
178 container->launch_menu_->PopupAsContext(gtk_get_current_event_time());
179 }
180
181 void BlockedPopupContainerViewGtk::OnCloseButtonClicked(
182 GtkButton *button, BlockedPopupContainerViewGtk* container) {
183 container->model_->set_dismissed();
184 container->model_->CloseAll();
185 }
186
OLDNEW
« no previous file with comments | « chrome/browser/gtk/blocked_popup_container_view_gtk.h ('k') | chrome/browser/tab_contents/tab_contents.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698