1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
// Copyright (c) 2011 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 "chrome/browser/ui/gtk/fullscreen_exit_bubble_gtk.h"
#include "chrome/browser/ui/gtk/gtk_chrome_link_button.h"
#include "chrome/browser/ui/gtk/gtk_util.h"
#include "chrome/browser/ui/gtk/rounded_window.h"
#include "grit/generated_resources.h"
#include "grit/ui_strings.h"
#include "ui/base/gtk/gtk_floating_container.h"
#include "ui/base/gtk/gtk_hig_constants.h"
#include "ui/base/l10n/l10n_util.h"
FullscreenExitBubbleGtk::FullscreenExitBubbleGtk(
GtkFloatingContainer* container,
CommandUpdater::CommandUpdaterDelegate* delegate)
: FullscreenExitBubble(delegate),
container_(container) {
InitWidgets();
StartWatchingMouse();
}
FullscreenExitBubbleGtk::~FullscreenExitBubbleGtk() {
}
void FullscreenExitBubbleGtk::InitWidgets() {
// The exit bubble is a gtk_chrome_link_button inside a gtk event box and gtk
// alignment (these provide the background color). This is then made rounded
// and put into a slide widget.
// The Windows code actually looks up the accelerator key in the accelerator
// table and then converts the key to a string (in a switch statement). This
// doesn't seem to be implemented for Gtk, so we just use F11 directly.
std::string exit_text_utf8("<span color=\"white\" size=\"large\">");
exit_text_utf8.append(l10n_util::GetStringFUTF8(
IDS_EXIT_FULLSCREEN_MODE, l10n_util::GetStringUTF16(IDS_APP_F11_KEY)));
exit_text_utf8.append("</span>");
GtkWidget* link = gtk_chrome_link_button_new_with_markup(
exit_text_utf8.c_str());
gtk_chrome_link_button_set_use_gtk_theme(GTK_CHROME_LINK_BUTTON(link),
FALSE);
signals_.Connect(link, "clicked", G_CALLBACK(OnLinkClickedThunk), this);
link_container_.Own(gtk_util::CreateGtkBorderBin(
link, &ui::kGdkBlack,
kPaddingPx, kPaddingPx, kPaddingPx, kPaddingPx));
GdkColor green = GDK_COLOR_RGB(0x00, 0xff, 0x00);
gtk_util::ActAsRoundedWindow(link_container_.get(), green, kPaddingPx,
gtk_util::ROUNDED_BOTTOM_LEFT | gtk_util::ROUNDED_BOTTOM_RIGHT,
gtk_util::BORDER_NONE);
slide_widget_.reset(new SlideAnimatorGtk(link_container_.get(),
SlideAnimatorGtk::DOWN, kSlideOutDurationMs, false, false, NULL));
gtk_widget_set_name(widget(), "exit-fullscreen-bubble");
gtk_widget_show_all(link_container_.get());
gtk_widget_show(widget());
slide_widget_->OpenWithoutAnimation();
gtk_floating_container_add_floating(GTK_FLOATING_CONTAINER(container_),
widget());
signals_.Connect(container_, "set-floating-position",
G_CALLBACK(OnSetFloatingPositionThunk), this);
}
gfx::Rect FullscreenExitBubbleGtk::GetPopupRect(
bool ignore_animation_state) const {
GtkRequisition bubble_size;
if (ignore_animation_state) {
gtk_widget_size_request(link_container_.get(), &bubble_size);
} else {
gtk_widget_size_request(widget(), &bubble_size);
}
return gfx::Rect(bubble_size.width, bubble_size.height);
}
gfx::Point FullscreenExitBubbleGtk::GetCursorScreenPoint() {
GdkDisplay* display = gtk_widget_get_display(widget());
// Get cursor position.
// TODO: this hits the X server, so we may want to consider decreasing
// kPositionCheckHz if we detect that we're running remotely.
int x, y;
gdk_display_get_pointer(display, NULL, &x, &y, NULL);
return gfx::Point(x, y);
}
bool FullscreenExitBubbleGtk::WindowContainsPoint(gfx::Point pos) {
GtkWindow* window = GTK_WINDOW(
gtk_widget_get_ancestor(widget(), GTK_TYPE_WINDOW));
int width, height, x, y;
gtk_window_get_size(window, &width, &height);
gtk_window_get_position(window, &x, &y);
return gfx::Rect(x, y, width, height).Contains(pos);
}
bool FullscreenExitBubbleGtk::IsWindowActive() {
if (!widget()->parent)
return false;
GtkWindow* window = GTK_WINDOW(
gtk_widget_get_ancestor(widget(), GTK_TYPE_WINDOW));
return gtk_window_is_active(window);
}
void FullscreenExitBubbleGtk::Hide() {
slide_widget_->Close();
}
void FullscreenExitBubbleGtk::Show() {
slide_widget_->Open();
}
bool FullscreenExitBubbleGtk::IsAnimating() {
return slide_widget_->IsAnimating();
}
void FullscreenExitBubbleGtk::OnSetFloatingPosition(
GtkWidget* floating_container,
GtkAllocation* allocation) {
GtkRequisition bubble_size;
gtk_widget_size_request(widget(), &bubble_size);
// Position the bubble at the top center of the screen.
GValue value = { 0, };
g_value_init(&value, G_TYPE_INT);
g_value_set_int(&value, (allocation->width - bubble_size.width) / 2);
gtk_container_child_set_property(GTK_CONTAINER(floating_container),
widget(), "x", &value);
g_value_set_int(&value, 0);
gtk_container_child_set_property(GTK_CONTAINER(floating_container),
widget(), "y", &value);
g_value_unset(&value);
}
void FullscreenExitBubbleGtk::OnLinkClicked(GtkWidget* link) {
ToggleFullscreen();
}
|