Home | History | Annotate | Download | only in automation
      1 // Copyright (c) 2011 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/utf_string_conversions.h"
     11 #include "chrome/browser/automation/automation_window_tracker.h"
     12 #include "chrome/browser/ui/gtk/gtk_util.h"
     13 #include "chrome/browser/ui/gtk/view_id_util.h"
     14 
     15 void TestingAutomationProvider::ActivateWindow(int handle) {
     16   NOTIMPLEMENTED();
     17 }
     18 
     19 void TestingAutomationProvider::IsWindowMaximized(int handle,
     20                                                   bool* is_maximized,
     21                                                   bool* success) {
     22   *success = false;
     23   NOTIMPLEMENTED();
     24 }
     25 
     26 void TestingAutomationProvider::TerminateSession(int handle, bool* success) {
     27   *success = false;
     28   NOTIMPLEMENTED();
     29 }
     30 
     31 #if !defined(TOOLKIT_VIEWS)
     32 void TestingAutomationProvider::WindowGetViewBounds(int handle,
     33                                                     int view_id,
     34                                                     bool screen_coordinates,
     35                                                     bool* success,
     36                                                     gfx::Rect* bounds) {
     37   *success = false;
     38 
     39   GtkWindow* window = window_tracker_->GetResource(handle);
     40   if (window) {
     41     GtkWidget* widget = ViewIDUtil::GetWidget(GTK_WIDGET(window),
     42                                               static_cast<ViewID>(view_id));
     43     if (!widget)
     44       return;
     45     *success = true;
     46     *bounds = gfx::Rect(widget->allocation.width, widget->allocation.height);
     47     gint x, y;
     48     if (screen_coordinates) {
     49       gfx::Point point = gtk_util::GetWidgetScreenPosition(widget);
     50       x = point.x();
     51       y = point.y();
     52     } else {
     53       gtk_widget_translate_coordinates(widget, GTK_WIDGET(window),
     54                                        0, 0, &x, &y);
     55     }
     56     bounds->set_origin(gfx::Point(x, y));
     57   }
     58 }
     59 #endif
     60 
     61 void TestingAutomationProvider::GetWindowBounds(int handle,
     62                                                 gfx::Rect* bounds,
     63                                                 bool* result) {
     64   *result = false;
     65   NOTIMPLEMENTED();
     66 }
     67 
     68 void TestingAutomationProvider::SetWindowBounds(int handle,
     69                                                 const gfx::Rect& bounds,
     70                                                 bool* success) {
     71   *success = false;
     72   GtkWindow* window = window_tracker_->GetResource(handle);
     73   if (window) {
     74     gtk_window_move(window, bounds.x(), bounds.height());
     75     gtk_window_resize(window, bounds.width(), bounds.height());
     76     *success = true;
     77   }
     78 }
     79 
     80 void TestingAutomationProvider::SetWindowVisible(int handle,
     81                                                  bool visible,
     82                                                  bool* result) {
     83   *result = false;
     84   GtkWindow* window = window_tracker_->GetResource(handle);
     85   if (window) {
     86     if (visible) {
     87       gtk_window_present(window);
     88     } else {
     89       gtk_widget_hide(GTK_WIDGET(window));
     90     }
     91     *result = true;
     92   }
     93 }
     94 
     95 void TestingAutomationProvider::GetWindowTitle(int handle, string16* text) {
     96   gfx::NativeWindow window = window_tracker_->GetResource(handle);
     97   const gchar* title = gtk_window_get_title(window);
     98   text->assign(UTF8ToUTF16(title));
     99 }
    100