<commit_before>// 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 "content/browser/renderer_host/render_widget_host.h"

#include <gdk/gdkx.h>
#include <gtk/gtk.h>

#include "base/synchronization/lock.h"
#include "content/browser/renderer_host/render_widget_host_view.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/x11/WebScreenInfoFactory.h"
#include "ui/gfx/gtk_native_view_id_manager.h"
#include "ui/gfx/rect.h"

using WebKit::WebScreenInfo;
using WebKit::WebScreenInfoFactory;

// We get a null |view| passed into this function please see
// http://crbug.com/9060 for more details.
void RenderWidgetHost::OnMsgGetScreenInfo(gfx::NativeViewId view,
                                          WebScreenInfo* results) {
  GtkWidget* widget = NULL;
  GdkWindow* gdk_window = NULL;
  if (GtkNativeViewManager::GetInstance()->GetNativeViewForId(
      &widget, view) && widget) {
    gdk_window = widget->window;
  } else {
    GdkDisplay* display = gdk_display_get_default();
    gdk_window = gdk_display_get_window_at_pointer(display, NULL, NULL);
  }
  if (!gdk_window)
    return;
  GdkScreen* screen = gdk_drawable_get_screen(gdk_window);
  *results = WebScreenInfoFactory::screenInfo(
      gdk_x11_drawable_get_xdisplay(gdk_window),
      gdk_x11_screen_get_screen_number(screen));

  // TODO(tony): We should move this code into WebScreenInfoFactory.
  int monitor_number = gdk_screen_get_monitor_at_window(screen, gdk_window);
  GdkRectangle monitor_rect;
  gdk_screen_get_monitor_geometry(screen, monitor_number, &monitor_rect);
  results->rect = WebKit::WebRect(monitor_rect.x, monitor_rect.y,
                                  monitor_rect.width, monitor_rect.height);
  // TODO(tony): Should we query _NET_WORKAREA to get the workarea?
  results->availableRect = results->rect;
}

// We get null window_ids passed into this function please see
// http://crbug.com/9060 for more details.<commit_msg>Fix a bug where window.screen would return 0, 0 as the width and height if the page requesting the dimensions didn't have a GDK window associated with it and there was no GDK window under the mouse pointer.<commit_after>// 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 "content/browser/renderer_host/render_widget_host.h"

#include <gdk/gdkx.h>
#include <gtk/gtk.h>

#include "base/synchronization/lock.h"
#include "content/browser/renderer_host/render_widget_host_view.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/x11/WebScreenInfoFactory.h"
#include "ui/gfx/gtk_native_view_id_manager.h"
#include "ui/gfx/rect.h"

using WebKit::WebScreenInfo;
using WebKit::WebScreenInfoFactory;

// We get a null |view| passed into this function please see
// http://crbug.com/9060 for more details.
void RenderWidgetHost::OnMsgGetScreenInfo(gfx::NativeViewId view,
                                          WebScreenInfo* results) {
  GtkWidget* widget = NULL;
  GdkWindow* gdk_window = NULL;
  if (GtkNativeViewManager::GetInstance()->GetNativeViewForId(
      &widget, view) && widget) {
    gdk_window = widget->window;
  } else {
    GdkDisplay* display = gdk_display_get_default();
    gdk_window = gdk_display_get_default_group(display);
  }
  if (!gdk_window)
    return;
  GdkScreen* screen = gdk_drawable_get_screen(gdk_window);
  *results = WebScreenInfoFactory::screenInfo(
      gdk_x11_drawable_get_xdisplay(gdk_window),
      gdk_x11_screen_get_screen_number(screen));

  // TODO(tony): We should move this code into WebScreenInfoFactory.
  int monitor_number = gdk_screen_get_monitor_at_window(screen, gdk_window);
  GdkRectangle monitor_rect;
  gdk_screen_get_monitor_geometry(screen, monitor_number, &monitor_rect);
  results->rect = WebKit::WebRect(monitor_rect.x, monitor_rect.y,
                                  monitor_rect.width, monitor_rect.height);
  // TODO(tony): Should we query _NET_WORKAREA to get the workarea?
  results->availableRect = results->rect;
}

// We get null window_ids passed into this function please see
// http://crbug.com/9060 for more details.
{'fraction_non_alphanumeric': 0.1002483630616392, 'fraction_numerical': 0.008579814856626778, 'mean_word_length': 4.3117505995203835, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6885207', 'n_tokens_mistral': 1453, 'n_tokens_neox': 1418, 'n_words': 332}