Fix most cpplint errors in inspectable_web_contents_view_linux.cc
This commit is contained in:
parent
1595940723
commit
4938fc62ad
1 changed files with 66 additions and 38 deletions
|
@ -1,4 +1,4 @@
|
|||
#include "inspectable_web_contents_view_linux.h"
|
||||
#include "browser/linux/inspectable_web_contents_view_linux.h"
|
||||
#include <glib-object.h>
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
|
@ -10,12 +10,15 @@
|
|||
|
||||
namespace brightray {
|
||||
|
||||
InspectableWebContentsView* CreateInspectableContentsView(InspectableWebContentsImpl* inspectable_web_contents) {
|
||||
InspectableWebContentsView* CreateInspectableContentsView(
|
||||
InspectableWebContentsImpl* inspectable_web_contents) {
|
||||
return new InspectableWebContentsViewLinux(inspectable_web_contents);
|
||||
}
|
||||
|
||||
InspectableWebContentsViewLinux::InspectableWebContentsViewLinux(InspectableWebContentsImpl* inspectable_web_contents)
|
||||
: inspectable_web_contents_(inspectable_web_contents), devtools_window_(NULL) {
|
||||
InspectableWebContentsViewLinux::InspectableWebContentsViewLinux(
|
||||
InspectableWebContentsImpl* inspectable_web_contents)
|
||||
: inspectable_web_contents_(inspectable_web_contents),
|
||||
devtools_window_(NULL) {
|
||||
}
|
||||
|
||||
InspectableWebContentsViewLinux::~InspectableWebContentsViewLinux() {
|
||||
|
@ -26,11 +29,13 @@ InspectableWebContentsViewLinux::~InspectableWebContentsViewLinux() {
|
|||
static void dump_one(GtkWidget *wat, int indent) {
|
||||
GtkAllocation alloc;
|
||||
gtk_widget_get_allocation(wat, &alloc);
|
||||
fprintf(stderr, "%*s[%p] %s @%d,%d %dx%d",
|
||||
fprintf(stderr, "%*s[%p] %s @%d,%d %dx%d",
|
||||
indent, "", wat,
|
||||
g_type_name_from_instance((GTypeInstance*)wat),
|
||||
alloc.x, alloc.y, alloc.width, alloc.height);
|
||||
if (GTK_IS_WINDOW(wat)) fprintf(stderr, " - \"%s\"", gtk_window_get_title(GTK_WINDOW(wat)));
|
||||
if (GTK_IS_WINDOW(wat)) {
|
||||
fprintf(stderr, " - \"%s\"", gtk_window_get_title(GTK_WINDOW(wat)));
|
||||
}
|
||||
fputc('\n', stderr);
|
||||
}
|
||||
|
||||
|
@ -41,21 +46,22 @@ static void dump_the_whole_tree(GtkWidget *wat, int indent) {
|
|||
}
|
||||
dump_one(wat, indent);
|
||||
GList *kids = gtk_container_get_children(GTK_CONTAINER(wat));
|
||||
for (GList *p=kids; p; p=p->next) {
|
||||
for (GList *p = kids; p; p = p->next) {
|
||||
dump_the_whole_tree(GTK_WIDGET(p->data), indent+2);
|
||||
}
|
||||
}
|
||||
|
||||
static void dump_parents(GtkWidget *wat) {
|
||||
fprintf(stderr, "Parents:\n");
|
||||
for (GtkWidget *p=gtk_widget_get_parent(wat); p; p=gtk_widget_get_parent(p)) {
|
||||
for (GtkWidget *p = gtk_widget_get_parent(wat); p; p = gtk_widget_get_parent(p)) {
|
||||
dump_one(p, 2);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
gfx::NativeView InspectableWebContentsViewLinux::GetNativeView() const {
|
||||
return inspectable_web_contents_->GetWebContents()->GetView()->GetNativeView();
|
||||
auto web_contents = inspectable_web_contents_->GetWebContents();
|
||||
return web_contents->GetView()->GetNativeView();
|
||||
}
|
||||
|
||||
|
||||
|
@ -90,18 +96,23 @@ gfx::NativeView InspectableWebContentsViewLinux::GetNativeView() const {
|
|||
*/
|
||||
|
||||
void InspectableWebContentsViewLinux::ShowDevTools() {
|
||||
GtkWidget *devtools = inspectable_web_contents()->devtools_web_contents()->GetView()->GetNativeView();
|
||||
auto devtools_web_contents =
|
||||
inspectable_web_contents()->devtools_web_contents();
|
||||
GtkWidget *devtools = devtools_web_contents->GetView()->GetNativeView();
|
||||
GtkWidget *parent = gtk_widget_get_parent(devtools);
|
||||
|
||||
DLOG(INFO) << base::StringPrintf("InspectableWebContentsViewLinux::ShowDevTools - parent=%s@%p window=%p dockside=\"%s\"",
|
||||
g_type_name_from_instance((GTypeInstance*)parent), parent, devtools_window_, dockside_.c_str());
|
||||
DLOG(INFO) << base::StringPrintf(
|
||||
"InspectableWebContentsViewLinux::ShowDevTools - parent=%s@%p window=%p dockside=\"%s\"",
|
||||
g_type_name_from_instance((GTypeInstance*)parent),
|
||||
parent,
|
||||
devtools_window_,
|
||||
dockside_.c_str());
|
||||
|
||||
if (!parent || GTK_IS_PANED(parent)) {
|
||||
if (dockside_ == "undocked") ShowDevToolsInWindow();
|
||||
else if (dockside_ == "bottom") ShowDevToolsInPane(true);
|
||||
else if (dockside_ == "right") ShowDevToolsInPane(false);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
DCHECK(parent == devtools_window_);
|
||||
if (dockside_ == "undocked") gtk_widget_show_all(parent);
|
||||
else if (dockside_ == "bottom") ShowDevToolsInPane(true);
|
||||
|
@ -110,16 +121,22 @@ void InspectableWebContentsViewLinux::ShowDevTools() {
|
|||
}
|
||||
|
||||
void InspectableWebContentsViewLinux::CloseDevTools() {
|
||||
GtkWidget *devtools = inspectable_web_contents()->devtools_web_contents()->GetView()->GetNativeView();
|
||||
auto devtools_web_contents =
|
||||
inspectable_web_contents()->devtools_web_contents();
|
||||
GtkWidget *devtools = devtools_web_contents->GetView()->GetNativeView();
|
||||
GtkWidget *parent = gtk_widget_get_parent(devtools);
|
||||
|
||||
DLOG(INFO) << base::StringPrintf("InspectableWebContentsViewLinux::CloseDevTools - parent=%s@%p window=%p dockside=\"%s\"",
|
||||
g_type_name_from_instance((GTypeInstance*)parent), parent, devtools_window_, dockside_.c_str());
|
||||
DLOG(INFO) << base::StringPrintf(
|
||||
"InspectableWebContentsViewLinux::CloseDevTools - parent=%s@%p window=%p dockside=\"%s\"",
|
||||
g_type_name_from_instance((GTypeInstance*)parent),
|
||||
parent,
|
||||
devtools_window_,
|
||||
dockside_.c_str());
|
||||
|
||||
if (!parent) {
|
||||
if (!parent)
|
||||
return; // Not visible -> nothing to do
|
||||
}
|
||||
else if (GTK_IS_PANED(parent)) {
|
||||
|
||||
if (GTK_IS_PANED(parent)) {
|
||||
GtkWidget *browser = GetBrowserWindow();
|
||||
GtkWidget *view = GetNativeView();
|
||||
|
||||
|
@ -129,22 +146,26 @@ void InspectableWebContentsViewLinux::CloseDevTools() {
|
|||
gtk_container_remove(GTK_CONTAINER(browser), parent);
|
||||
gtk_widget_reparent(view, browser);
|
||||
g_object_unref(parent);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
DCHECK(parent == devtools_window_);
|
||||
gtk_widget_hide(parent);
|
||||
}
|
||||
}
|
||||
|
||||
bool InspectableWebContentsViewLinux::SetDockSide(const std::string& side) {
|
||||
DLOG(INFO) << "InspectableWebContentsViewLinux::SetDockSide: \"" << side << "\"";
|
||||
if (side != "undocked" && side != "bottom" && side != "right") return false; // unsupported display location
|
||||
if (dockside_ == side) return true; // no change from current location
|
||||
DLOG(INFO) <<
|
||||
"InspectableWebContentsViewLinux::SetDockSide: \"" << side << "\"";
|
||||
if (side != "undocked" && side != "bottom" && side != "right")
|
||||
return false; // unsupported display location
|
||||
if (dockside_ == side)
|
||||
return true; // no change from current location
|
||||
|
||||
dockside_ = side;
|
||||
|
||||
// If devtools already has a parent, then we're being asked to move it.
|
||||
GtkWidget *devtools = inspectable_web_contents()->devtools_web_contents()->GetView()->GetNativeView();
|
||||
auto devtools_web_contents =
|
||||
inspectable_web_contents()->devtools_web_contents();
|
||||
GtkWidget *devtools = devtools_web_contents->GetView()->GetNativeView();
|
||||
if (gtk_widget_get_parent(devtools)) {
|
||||
ShowDevTools();
|
||||
}
|
||||
|
@ -153,14 +174,16 @@ bool InspectableWebContentsViewLinux::SetDockSide(const std::string& side) {
|
|||
}
|
||||
|
||||
void InspectableWebContentsViewLinux::ShowDevToolsInWindow() {
|
||||
GtkWidget *devtools = inspectable_web_contents()->devtools_web_contents()->GetView()->GetNativeView();
|
||||
auto devtools_web_contents =
|
||||
inspectable_web_contents()->devtools_web_contents();
|
||||
GtkWidget *devtools = devtools_web_contents->GetView()->GetNativeView();
|
||||
GtkWidget *parent = gtk_widget_get_parent(devtools);
|
||||
|
||||
if (!devtools_window_) MakeDevToolsWindow();
|
||||
if (!devtools_window_)
|
||||
MakeDevToolsWindow();
|
||||
if (!parent) {
|
||||
gtk_container_add(GTK_CONTAINER(devtools_window_), devtools);
|
||||
}
|
||||
else if (parent != devtools_window_) {
|
||||
} else if (parent != devtools_window_) {
|
||||
DCHECK(GTK_IS_PANED(parent));
|
||||
gtk_widget_reparent(devtools, devtools_window_);
|
||||
|
||||
|
@ -181,11 +204,16 @@ void InspectableWebContentsViewLinux::MakeDevToolsWindow() {
|
|||
devtools_window_ = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
||||
gtk_window_set_title(GTK_WINDOW(devtools_window_), "Developer Tools");
|
||||
gtk_window_set_default_size(GTK_WINDOW(devtools_window_), 800, 600);
|
||||
g_signal_connect(GTK_OBJECT(devtools_window_), "delete-event", G_CALLBACK(gtk_widget_hide_on_delete), this);
|
||||
g_signal_connect(GTK_OBJECT(devtools_window_),
|
||||
"delete-event",
|
||||
G_CALLBACK(gtk_widget_hide_on_delete),
|
||||
this);
|
||||
}
|
||||
|
||||
void InspectableWebContentsViewLinux::ShowDevToolsInPane(bool on_bottom) {
|
||||
GtkWidget *devtools = inspectable_web_contents()->devtools_web_contents()->GetView()->GetNativeView();
|
||||
auto devtools_web_contents =
|
||||
inspectable_web_contents()->devtools_web_contents();
|
||||
GtkWidget *devtools = devtools_web_contents->GetView()->GetNativeView();
|
||||
GtkWidget *parent = gtk_widget_get_parent(devtools);
|
||||
GtkWidget *pane = on_bottom ? gtk_vpaned_new() : gtk_hpaned_new();
|
||||
GtkWidget *view = GetNativeView();
|
||||
|
@ -193,15 +221,15 @@ void InspectableWebContentsViewLinux::ShowDevToolsInPane(bool on_bottom) {
|
|||
|
||||
GtkAllocation alloc;
|
||||
gtk_widget_get_allocation(browser, &alloc);
|
||||
gtk_paned_set_position(GTK_PANED(pane), on_bottom ? alloc.height*2/3 : alloc.width/2);
|
||||
gtk_paned_set_position(GTK_PANED(pane),
|
||||
on_bottom ? alloc.height * 2 / 3 : alloc.width / 2);
|
||||
if (!parent) {
|
||||
g_object_ref(view);
|
||||
gtk_container_remove(GTK_CONTAINER(browser), view);
|
||||
gtk_paned_add1(GTK_PANED(pane), view);
|
||||
gtk_paned_add2(GTK_PANED(pane), devtools);
|
||||
g_object_unref(view);
|
||||
}
|
||||
else if (GTK_IS_PANED(parent)) {
|
||||
} else if (GTK_IS_PANED(parent)) {
|
||||
g_object_ref(view);
|
||||
g_object_ref(devtools);
|
||||
gtk_container_remove(GTK_CONTAINER(parent), view);
|
||||
|
@ -211,8 +239,7 @@ void InspectableWebContentsViewLinux::ShowDevToolsInPane(bool on_bottom) {
|
|||
g_object_unref(view);
|
||||
g_object_unref(devtools);
|
||||
gtk_container_remove(GTK_CONTAINER(browser), parent);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
DCHECK(parent == devtools_window_);
|
||||
g_object_ref(view);
|
||||
gtk_container_remove(GTK_CONTAINER(devtools_window_), devtools);
|
||||
|
@ -229,7 +256,8 @@ void InspectableWebContentsViewLinux::ShowDevToolsInPane(bool on_bottom) {
|
|||
GtkWidget *InspectableWebContentsViewLinux::GetBrowserWindow() {
|
||||
GtkWidget *view = GetNativeView();
|
||||
GtkWidget *parent = gtk_widget_get_parent(view);
|
||||
GtkWidget *browser = GTK_IS_PANED(parent) ? gtk_widget_get_parent(parent) : parent;
|
||||
GtkWidget *browser =
|
||||
GTK_IS_PANED(parent) ? gtk_widget_get_parent(parent) : parent;
|
||||
DCHECK(GTK_IS_WINDOW(browser));
|
||||
return browser;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue