Home | History | Annotate | Download | only in automation
      1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #include "chrome/browser/automation/testing_automation_provider.h"
      6 
      7 #include <gtk/gtk.h>
      8 
      9 #include "base/logging.h"
     10 #include "base/strings/utf_string_conversions.h"
     11 #include "chrome/browser/automation/automation_window_tracker.h"
     12 #include "chrome/browser/ui/gtk/view_id_util.h"
     13 #include "ui/base/gtk/gtk_screen_util.h"
     14 
     15 void TestingAutomationProvider::TerminateSession(int handle, bool* success) {
     16   *success = false;
     17   NOTIMPLEMENTED();
     18 }
     19 
     20 void TestingAutomationProvider::WindowGetViewBounds(int handle,
     21                                                     int view_id,
     22                                                     bool screen_coordinates,
     23                                                     bool* success,
     24                                                     gfx::Rect* bounds) {
     25   *success = false;
     26 
     27   GtkWindow* window = window_tracker_->GetResource(handle);
     28   if (window) {
     29     GtkWidget* widget = ViewIDUtil::GetWidget(GTK_WIDGET(window),
     30                                               static_cast<ViewID>(view_id));
     31     if (!widget)
     32       return;
     33     *success = true;
     34 
     35     GtkAllocation allocation;
     36     gtk_widget_get_allocation(widget, &allocation);
     37     *bounds = gfx::Rect(allocation.width, allocation.height);
     38     gfx::Point origin;
     39     if (screen_coordinates) {
     40       origin = gfx::PointAtOffsetFromOrigin(ui::GetWidgetScreenOffset(widget));
     41     } else {
     42       gint x, y;
     43       gtk_widget_translate_coordinates(widget, GTK_WIDGET(window),
     44                                        0, 0, &x, &y);
     45       origin = gfx::Point(x, y);
     46     }
     47     bounds->set_origin(origin);
     48   }
     49 }
     50 
     51 void TestingAutomationProvider::SetWindowBounds(int handle,
     52                                                 const gfx::Rect& bounds,
     53                                                 bool* success) {
     54   *success = false;
     55   GtkWindow* window = window_tracker_->GetResource(handle);
     56   if (window) {
     57     gtk_window_move(window, bounds.x(), bounds.height());
     58     gtk_window_resize(window, bounds.width(), bounds.height());
     59     *success = true;
     60   }
     61 }
     62