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 "chrome/browser/automation/automation_window_tracker.h"
      8 #include "ui/views/view.h"
      9 #include "ui/views/widget/widget.h"
     10 
     11 void TestingAutomationProvider::WindowGetViewBounds(int handle,
     12                                                     int view_id,
     13                                                     bool screen_coordinates,
     14                                                     bool* success,
     15                                                     gfx::Rect* bounds) {
     16   *success = false;
     17 
     18   if (window_tracker_->ContainsHandle(handle)) {
     19     gfx::NativeWindow window = window_tracker_->GetResource(handle);
     20     views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window);
     21     if (widget) {
     22       views::View* root_view = widget->GetRootView();
     23       views::View* view = root_view->GetViewByID(view_id);
     24       if (view) {
     25         *success = true;
     26         gfx::Point point;
     27         if (screen_coordinates)
     28           views::View::ConvertPointToScreen(view, &point);
     29         else
     30           views::View::ConvertPointToTarget(view, root_view, &point);
     31         *bounds = view->GetContentsBounds();
     32         bounds->set_origin(point);
     33       }
     34     }
     35   }
     36 }
     37