Fix most cpplint errors in inspectable_web_contents_view_linux.cc

This commit is contained in:
Adam Roben 2013-11-17 19:12:50 -05:00
parent 1595940723
commit 4938fc62ad

View file

@ -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 <glib-object.h>
#include <gtk/gtk.h> #include <gtk/gtk.h>
@ -10,12 +10,15 @@
namespace brightray { namespace brightray {
InspectableWebContentsView* CreateInspectableContentsView(InspectableWebContentsImpl* inspectable_web_contents) { InspectableWebContentsView* CreateInspectableContentsView(
InspectableWebContentsImpl* inspectable_web_contents) {
return new InspectableWebContentsViewLinux(inspectable_web_contents); return new InspectableWebContentsViewLinux(inspectable_web_contents);
} }
InspectableWebContentsViewLinux::InspectableWebContentsViewLinux(InspectableWebContentsImpl* inspectable_web_contents) InspectableWebContentsViewLinux::InspectableWebContentsViewLinux(
: inspectable_web_contents_(inspectable_web_contents), devtools_window_(NULL) { InspectableWebContentsImpl* inspectable_web_contents)
: inspectable_web_contents_(inspectable_web_contents),
devtools_window_(NULL) {
} }
InspectableWebContentsViewLinux::~InspectableWebContentsViewLinux() { InspectableWebContentsViewLinux::~InspectableWebContentsViewLinux() {
@ -30,7 +33,9 @@ static void dump_one(GtkWidget *wat, int indent) {
indent, "", wat, indent, "", wat,
g_type_name_from_instance((GTypeInstance*)wat), g_type_name_from_instance((GTypeInstance*)wat),
alloc.x, alloc.y, alloc.width, alloc.height); 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); fputc('\n', stderr);
} }
@ -55,7 +60,8 @@ static void dump_parents(GtkWidget *wat) {
#endif #endif
gfx::NativeView InspectableWebContentsViewLinux::GetNativeView() const { 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() { 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); GtkWidget *parent = gtk_widget_get_parent(devtools);
DLOG(INFO) << base::StringPrintf("InspectableWebContentsViewLinux::ShowDevTools - parent=%s@%p window=%p dockside=\"%s\"", DLOG(INFO) << base::StringPrintf(
g_type_name_from_instance((GTypeInstance*)parent), parent, devtools_window_, dockside_.c_str()); "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 (!parent || GTK_IS_PANED(parent)) {
if (dockside_ == "undocked") ShowDevToolsInWindow(); if (dockside_ == "undocked") ShowDevToolsInWindow();
else if (dockside_ == "bottom") ShowDevToolsInPane(true); else if (dockside_ == "bottom") ShowDevToolsInPane(true);
else if (dockside_ == "right") ShowDevToolsInPane(false); else if (dockside_ == "right") ShowDevToolsInPane(false);
} } else {
else {
DCHECK(parent == devtools_window_); DCHECK(parent == devtools_window_);
if (dockside_ == "undocked") gtk_widget_show_all(parent); if (dockside_ == "undocked") gtk_widget_show_all(parent);
else if (dockside_ == "bottom") ShowDevToolsInPane(true); else if (dockside_ == "bottom") ShowDevToolsInPane(true);
@ -110,16 +121,22 @@ void InspectableWebContentsViewLinux::ShowDevTools() {
} }
void InspectableWebContentsViewLinux::CloseDevTools() { 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); GtkWidget *parent = gtk_widget_get_parent(devtools);
DLOG(INFO) << base::StringPrintf("InspectableWebContentsViewLinux::CloseDevTools - parent=%s@%p window=%p dockside=\"%s\"", DLOG(INFO) << base::StringPrintf(
g_type_name_from_instance((GTypeInstance*)parent), parent, devtools_window_, dockside_.c_str()); "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 return; // Not visible -> nothing to do
}
else if (GTK_IS_PANED(parent)) { if (GTK_IS_PANED(parent)) {
GtkWidget *browser = GetBrowserWindow(); GtkWidget *browser = GetBrowserWindow();
GtkWidget *view = GetNativeView(); GtkWidget *view = GetNativeView();
@ -129,22 +146,26 @@ void InspectableWebContentsViewLinux::CloseDevTools() {
gtk_container_remove(GTK_CONTAINER(browser), parent); gtk_container_remove(GTK_CONTAINER(browser), parent);
gtk_widget_reparent(view, browser); gtk_widget_reparent(view, browser);
g_object_unref(parent); g_object_unref(parent);
} } else {
else {
DCHECK(parent == devtools_window_); DCHECK(parent == devtools_window_);
gtk_widget_hide(parent); gtk_widget_hide(parent);
} }
} }
bool InspectableWebContentsViewLinux::SetDockSide(const std::string& side) { bool InspectableWebContentsViewLinux::SetDockSide(const std::string& side) {
DLOG(INFO) << "InspectableWebContentsViewLinux::SetDockSide: \"" << side << "\""; DLOG(INFO) <<
if (side != "undocked" && side != "bottom" && side != "right") return false; // unsupported display location "InspectableWebContentsViewLinux::SetDockSide: \"" << side << "\"";
if (dockside_ == side) return true; // no change from current location if (side != "undocked" && side != "bottom" && side != "right")
return false; // unsupported display location
if (dockside_ == side)
return true; // no change from current location
dockside_ = side; dockside_ = side;
// If devtools already has a parent, then we're being asked to move it. // 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)) { if (gtk_widget_get_parent(devtools)) {
ShowDevTools(); ShowDevTools();
} }
@ -153,14 +174,16 @@ bool InspectableWebContentsViewLinux::SetDockSide(const std::string& side) {
} }
void InspectableWebContentsViewLinux::ShowDevToolsInWindow() { 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); GtkWidget *parent = gtk_widget_get_parent(devtools);
if (!devtools_window_) MakeDevToolsWindow(); if (!devtools_window_)
MakeDevToolsWindow();
if (!parent) { if (!parent) {
gtk_container_add(GTK_CONTAINER(devtools_window_), devtools); gtk_container_add(GTK_CONTAINER(devtools_window_), devtools);
} } else if (parent != devtools_window_) {
else if (parent != devtools_window_) {
DCHECK(GTK_IS_PANED(parent)); DCHECK(GTK_IS_PANED(parent));
gtk_widget_reparent(devtools, devtools_window_); gtk_widget_reparent(devtools, devtools_window_);
@ -181,11 +204,16 @@ void InspectableWebContentsViewLinux::MakeDevToolsWindow() {
devtools_window_ = gtk_window_new(GTK_WINDOW_TOPLEVEL); devtools_window_ = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(devtools_window_), "Developer Tools"); gtk_window_set_title(GTK_WINDOW(devtools_window_), "Developer Tools");
gtk_window_set_default_size(GTK_WINDOW(devtools_window_), 800, 600); 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) { 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 *parent = gtk_widget_get_parent(devtools);
GtkWidget *pane = on_bottom ? gtk_vpaned_new() : gtk_hpaned_new(); GtkWidget *pane = on_bottom ? gtk_vpaned_new() : gtk_hpaned_new();
GtkWidget *view = GetNativeView(); GtkWidget *view = GetNativeView();
@ -193,15 +221,15 @@ void InspectableWebContentsViewLinux::ShowDevToolsInPane(bool on_bottom) {
GtkAllocation alloc; GtkAllocation alloc;
gtk_widget_get_allocation(browser, &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) { if (!parent) {
g_object_ref(view); g_object_ref(view);
gtk_container_remove(GTK_CONTAINER(browser), view); gtk_container_remove(GTK_CONTAINER(browser), view);
gtk_paned_add1(GTK_PANED(pane), view); gtk_paned_add1(GTK_PANED(pane), view);
gtk_paned_add2(GTK_PANED(pane), devtools); gtk_paned_add2(GTK_PANED(pane), devtools);
g_object_unref(view); g_object_unref(view);
} } else if (GTK_IS_PANED(parent)) {
else if (GTK_IS_PANED(parent)) {
g_object_ref(view); g_object_ref(view);
g_object_ref(devtools); g_object_ref(devtools);
gtk_container_remove(GTK_CONTAINER(parent), view); gtk_container_remove(GTK_CONTAINER(parent), view);
@ -211,8 +239,7 @@ void InspectableWebContentsViewLinux::ShowDevToolsInPane(bool on_bottom) {
g_object_unref(view); g_object_unref(view);
g_object_unref(devtools); g_object_unref(devtools);
gtk_container_remove(GTK_CONTAINER(browser), parent); gtk_container_remove(GTK_CONTAINER(browser), parent);
} } else {
else {
DCHECK(parent == devtools_window_); DCHECK(parent == devtools_window_);
g_object_ref(view); g_object_ref(view);
gtk_container_remove(GTK_CONTAINER(devtools_window_), devtools); gtk_container_remove(GTK_CONTAINER(devtools_window_), devtools);
@ -229,7 +256,8 @@ void InspectableWebContentsViewLinux::ShowDevToolsInPane(bool on_bottom) {
GtkWidget *InspectableWebContentsViewLinux::GetBrowserWindow() { GtkWidget *InspectableWebContentsViewLinux::GetBrowserWindow() {
GtkWidget *view = GetNativeView(); GtkWidget *view = GetNativeView();
GtkWidget *parent = gtk_widget_get_parent(view); 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)); DCHECK(GTK_IS_WINDOW(browser));
return browser; return browser;
} }