<commit_before>// Copyright (c) 2009 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 "chrome/browser/gtk/tabs/dragged_tab_gtk.h"

#include <gdk/gdk.h>

#include <algorithm>

#include "app/gfx/canvas_paint.h"
#include "base/gfx/gtk_util.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/browser/tabs/tab_strip_model.h"
#include "chrome/browser/gtk/tabs/tab_renderer_gtk.h"
#include "chrome/common/gtk_util.h"
#include "chrome/common/x11_util.h"
#include "third_party/skia/include/core/SkShader.h"

namespace {

// The size of the dragged window frame.
const int kDragFrameBorderSize = 1;
const int kTwiceDragFrameBorderSize = 2 * kDragFrameBorderSize;

// Used to scale the dragged window sizes.
const float kScalingFactor = 0.5;

const int kAnimateToBoundsDurationMs = 150;

const gdouble kTransparentAlpha = (200.0f / 255.0f);
const gdouble kOpaqueAlpha = 1.0f;
const double kDraggedTabBorderColor[] = { 103.0 / 0xff,
                                          129.0 / 0xff,
                                          162.0 / 0xff };

}  // namespace

////////////////////////////////////////////////////////////////////////////////
// DraggedTabGtk, public:

DraggedTabGtk::DraggedTabGtk(TabContents* datasource,
                             const gfx::Point& mouse_tab_offset,
                             const gfx::Size& contents_size)
    : backing_store_(NULL),
      renderer_(new TabRendererGtk(datasource->profile()->GetThemeProvider())),
      attached_(false),
      mouse_tab_offset_(mouse_tab_offset),
      attached_tab_size_(TabRendererGtk::GetMinimumSelectedSize()),
      contents_size_(contents_size),
      close_animation_(this),
      tab_width_(0) {
  renderer_->UpdateData(datasource, false);

  container_ = gtk_window_new(GTK_WINDOW_POPUP);
  SetContainerColorMap();
  gtk_widget_set_app_paintable(container_, TRUE);
  g_signal_connect(G_OBJECT(container_), "expose-event",
                   G_CALLBACK(OnExposeEvent), this);
  gtk_widget_add_events(container_, GDK_STRUCTURE_MASK);
  gtk_container_add(GTK_CONTAINER(container_), renderer_->widget());
  gtk_widget_show_all(container_);
}

DraggedTabGtk::~DraggedTabGtk() {
  gtk_widget_destroy(container_);
}

void DraggedTabGtk::MoveTo(const gfx::Point& screen_point) {
  int x = screen_point.x() + mouse_tab_offset_.x() -
      ScaleValue(mouse_tab_offset_.x());
  int y = screen_point.y() + mouse_tab_offset_.y() -
      ScaleValue(mouse_tab_offset_.y());

  gtk_window_move(GTK_WINDOW(container_), x, y);
}

void DraggedTabGtk::Attach(int selected_width) {
  attached_ = true;
  Resize(selected_width);

  if (gtk_util::IsScreenComposited())
    gdk_window_set_opacity(container_->window, kOpaqueAlpha);
}

void DraggedTabGtk::Resize(int width) {
  attached_tab_size_.set_width(width);
  ResizeContainer();
}

void DraggedTabGtk::set_pinned(bool pinned) {
  renderer_->set_pinned(pinned);
}

bool DraggedTabGtk::is_pinned() const {
  return renderer_->is_pinned();
}

void DraggedTabGtk::Detach(GtkWidget* contents, BackingStore* backing_store) {
  // Detached tabs are never pinned.
  renderer_->set_pinned(false);

  if (attached_tab_size_.width() != tab_width_) {
    // The attached tab size differs from current tab size. Resize accordingly.
    Resize(tab_width_);
  }

  attached_ = false;
  contents_ = contents;
  backing_store_ = backing_store;
  ResizeContainer();

  if (gtk_util::IsScreenComposited())
    gdk_window_set_opacity(container_->window, kTransparentAlpha);
}

void DraggedTabGtk::Update() {
  gtk_widget_queue_draw(container_);
}

void DraggedTabGtk::AnimateToBounds(const gfx::Rect& bounds,
                                    AnimateToBoundsCallback* callback) {
  animation_callback_.reset(callback);

  gint x, y, width, height;
  gdk_window_get_origin(container_->window, &x, &y);
  gdk_window_get_geometry(container_->window, NULL, NULL,
                          &width, &height, NULL);

  animation_start_bounds_ = gfx::Rect(x, y, width, height);
  animation_end_bounds_ = bounds;

  close_animation_.SetSlideDuration(kAnimateToBoundsDurationMs);
  close_animation_.SetTweenType(SlideAnimation::EASE_OUT);
  if (!close_animation_.IsShowing()) {
    close_animation_.Reset();
    close_animation_.Show();
  }
}

////////////////////////////////////////////////////////////////////////////////
// DraggedTabGtk, AnimationDelegate implementation:

void DraggedTabGtk::AnimationProgressed(const Animation* animation) {
  int delta_x = (animation_end_bounds_.x() - animation_start_bounds_.x());
  int x = animation_start_bounds_.x() +
      static_cast<int>(delta_x * animation->GetCurrentValue());
  int y = animation_end_bounds_.y();
  gdk_window_move(container_->window, x, y);
}

void DraggedTabGtk::AnimationEnded(const Animation* animation) {
  animation_callback_->Run();
}

void DraggedTabGtk::AnimationCanceled(const Animation* animation) {
  AnimationEnded(animation);
}

////////////////////////////////////////////////////////////////////////////////
// DraggedTabGtk, private:

void DraggedTabGtk::Layout() {
  if (attached_) {
    gfx::Size prefsize = GetPreferredSize();
    renderer_->SetBounds(gfx::Rect(0, 0, prefsize.width(), prefsize.height()));
  } else {
    // TODO(jhawkins): RTL layout.

    // The renderer_'s width should be attached_tab_size_.width() in both LTR
    // and RTL locales. Wrong width will cause the wrong positioning of the tab
    // view in dragging. Please refer to http://crbug.com/6223 for details.
    renderer_->SetBounds(gfx::Rect(0, 0, attached_tab_size_.width(),
                         attached_tab_size_.height()));
  }
}

gfx::Size DraggedTabGtk::GetPreferredSize() {
  if (attached_)
    return attached_tab_size_;

  int width = std::max(attached_tab_size_.width(), contents_size_.width()) +
      kTwiceDragFrameBorderSize;
  int height = attached_tab_size_.height() + kDragFrameBorderSize +
      contents_size_.height();
  return gfx::Size(width, height);
}

void DraggedTabGtk::ResizeContainer() {
  gfx::Size size = GetPreferredSize();
  gtk_window_resize(GTK_WINDOW(container_),
                    ScaleValue(size.width()), ScaleValue(size.height()));
  Layout();
}

int DraggedTabGtk::ScaleValue(int value) {
  return attached_ ? value : static_cast<int>(value * kScalingFactor);
}

gfx::Rect DraggedTabGtk::bounds() const {
  gint x, y, width, height;
  gtk_window_get_position(GTK_WINDOW(container_), &x, &y);
  gtk_window_get_size(GTK_WINDOW(container_), &width, &height);
  return gfx::Rect(x, y, width, height);
}

void DraggedTabGtk::SetContainerColorMap() {
  GdkScreen* screen = gtk_widget_get_screen(container_);
  GdkColormap* colormap = gdk_screen_get_rgba_colormap(screen);

  // If rgba is not available, use rgb instead.
  if (!colormap)
    colormap = gdk_screen_get_rgb_colormap(screen);

  gtk_widget_set_colormap(container_, colormap);
}

void DraggedTabGtk::SetContainerTransparency() {
  cairo_t* cairo_context = gdk_cairo_create(container_->window);
  if (!cairo_context)
    return;

  // Make the background of the dragged tab window fully transparent.  All of
  // the content of the window (child widgets) will be completely opaque.
  gfx::Size size = bounds().size();
  cairo_scale(cairo_context, static_cast<double>(size.width()),
              static_cast<double>(size.height()));
  cairo_set_source_rgba(cairo_context, 1.0f, 1.0f, 1.0f, 0.0f);
  cairo_set_operator(cairo_context, CAIRO_OPERATOR_SOURCE);
  cairo_paint(cairo_context);
  cairo_destroy(cairo_context);
}

void DraggedTabGtk::SetContainerShapeMask(GdkPixbuf* pixbuf) {
  // Create a 1bpp bitmap the size of |container_|.
  gfx::Size size = bounds().size();
  GdkPixmap* pixmap = gdk_pixmap_new(NULL, size.width(), size.height(), 1);
  cairo_t* cairo_context = gdk_cairo_create(GDK_DRAWABLE(pixmap));

  // Set the transparency.
  cairo_set_source_rgba(cairo_context, 1.0f, 1.0f, 1.0f, 0.0f);

  // Blit the rendered bitmap into a pixmap.  Any pixel set in the pixmap will
  // be opaque in the container window.
  cairo_set_operator(cairo_context, CAIRO_OPERATOR_SOURCE);
  if (!attached_)
    cairo_scale(cairo_context, kScalingFactor, kScalingFactor);
  gdk_cairo_set_source_pixbuf(cairo_context, pixbuf, 0, 0);
  cairo_paint(cairo_context);

  if (!attached_) {
    // Make the render area depiction opaque (leaving enough room for the
    // border).
    cairo_identity_matrix(cairo_context);
    cairo_set_source_rgba(cairo_context, 1.0f, 1.0f, 1.0f, 1.0f);
    int tab_height = kScalingFactor * gdk_pixbuf_get_height(pixbuf) -
                     kDragFrameBorderSize;
    cairo_rectangle(cairo_context,
                    0, tab_height,
                    size.width(), size.height() - tab_height);
    cairo_fill(cairo_context);
  }

  cairo_destroy(cairo_context);

  // Set the shape mask.
  gdk_window_shape_combine_mask(container_->window, pixmap, 0, 0);
  g_object_unref(pixmap);
}

GdkPixbuf* DraggedTabGtk::PaintTab() {
  SkBitmap bitmap = renderer_->PaintBitmap();
  return gfx::GdkPixbufFromSkBitmap(&bitmap);
}

// static
gboolean DraggedTabGtk::OnExposeEvent(GtkWidget* widget,
                                      GdkEventExpose* event,
                                      DraggedTabGtk* dragged_tab) {
  GdkPixbuf* pixbuf = dragged_tab->PaintTab();
  if (gtk_util::IsScreenComposited()) {
    dragged_tab->SetContainerTransparency();
  } else {
    dragged_tab->SetContainerShapeMask(pixbuf);
  }

  // Only used when not attached.
  int tab_height = kScalingFactor * gdk_pixbuf_get_height(pixbuf);
  int tab_width = kScalingFactor * gdk_pixbuf_get_width(pixbuf);

  // Draw the render area.
  if (dragged_tab->backing_store_ && !dragged_tab->attached_) {
    // This leaves room for the border.
    dragged_tab->backing_store_->PaintToRect(
        gfx::Rect(kDragFrameBorderSize, tab_height,
                  widget->allocation.width - kTwiceDragFrameBorderSize,
                  widget->allocation.height - tab_height -
                  kDragFrameBorderSize),
        GDK_DRAWABLE(widget->window));
  }

  cairo_t* cr = gdk_cairo_create(GDK_DRAWABLE(widget->window));
  // Draw the border.
  if (!dragged_tab->attached_) {
    cairo_set_line_width(cr, kDragFrameBorderSize);
    cairo_set_source_rgb(cr, kDraggedTabBorderColor[0],
                             kDraggedTabBorderColor[1],
                             kDraggedTabBorderColor[2]);
    // |offset| is the distance from the edge of the image to the middle of
    // the border line.
    double offset = kDragFrameBorderSize / 2.0 - 0.5;
    double left_x = offset;
    double top_y = tab_height - kDragFrameBorderSize + offset;
    double right_x = widget->allocation.width - offset;
    double bottom_y = widget->allocation.height - offset;
    double middle_x = tab_width + offset;

    // We don't use cairo_rectangle() because we don't want to draw the border
    // under the tab itself.
    cairo_move_to(cr, left_x, top_y);
    cairo_line_to(cr, left_x, bottom_y);
    cairo_line_to(cr, right_x, bottom_y);
    cairo_line_to(cr, right_x, top_y);
    cairo_line_to(cr, middle_x, top_y);
    cairo_stroke(cr);
  }

  // Draw the tab.
  if (!dragged_tab->attached_)
    cairo_scale(cr, kScalingFactor, kScalingFactor);
  gdk_cairo_set_source_pixbuf(cr, pixbuf, 0, 0);
  cairo_paint(cr);

  cairo_destroy(cr);

  g_object_unref(pixbuf);

  // We've already drawn the tab, so don't propagate the expose-event signal.
  return TRUE;
}
<commit_msg>gtk: Handle RTL layout when rendering the dragged tab.<commit_after>// Copyright (c) 2009 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 "chrome/browser/gtk/tabs/dragged_tab_gtk.h"

#include <gdk/gdk.h>

#include <algorithm>

#include "app/gfx/canvas_paint.h"
#include "app/l10n_util.h"
#include "base/gfx/gtk_util.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/browser/tabs/tab_strip_model.h"
#include "chrome/browser/gtk/tabs/tab_renderer_gtk.h"
#include "chrome/common/gtk_util.h"
#include "chrome/common/x11_util.h"
#include "third_party/skia/include/core/SkShader.h"

namespace {

// The size of the dragged window frame.
const int kDragFrameBorderSize = 1;
const int kTwiceDragFrameBorderSize = 2 * kDragFrameBorderSize;

// Used to scale the dragged window sizes.
const float kScalingFactor = 0.5;

const int kAnimateToBoundsDurationMs = 150;

const gdouble kTransparentAlpha = (200.0f / 255.0f);
const gdouble kOpaqueAlpha = 1.0f;
const double kDraggedTabBorderColor[] = { 103.0 / 0xff,
                                          129.0 / 0xff,
                                          162.0 / 0xff };

}  // namespace

////////////////////////////////////////////////////////////////////////////////
// DraggedTabGtk, public:

DraggedTabGtk::DraggedTabGtk(TabContents* datasource,
                             const gfx::Point& mouse_tab_offset,
                             const gfx::Size& contents_size)
    : backing_store_(NULL),
      renderer_(new TabRendererGtk(datasource->profile()->GetThemeProvider())),
      attached_(false),
      mouse_tab_offset_(mouse_tab_offset),
      attached_tab_size_(TabRendererGtk::GetMinimumSelectedSize()),
      contents_size_(contents_size),
      close_animation_(this),
      tab_width_(0) {
  renderer_->UpdateData(datasource, false);

  container_ = gtk_window_new(GTK_WINDOW_POPUP);
  SetContainerColorMap();
  gtk_widget_set_app_paintable(container_, TRUE);
  g_signal_connect(G_OBJECT(container_), "expose-event",
                   G_CALLBACK(OnExposeEvent), this);
  gtk_widget_add_events(container_, GDK_STRUCTURE_MASK);
  gtk_container_add(GTK_CONTAINER(container_), renderer_->widget());
  gtk_widget_show_all(container_);
}

DraggedTabGtk::~DraggedTabGtk() {
  gtk_widget_destroy(container_);
}

void DraggedTabGtk::MoveTo(const gfx::Point& screen_point) {
  int x = screen_point.x() + mouse_tab_offset_.x() -
      ScaleValue(mouse_tab_offset_.x());
  int y = screen_point.y() + mouse_tab_offset_.y() -
      ScaleValue(mouse_tab_offset_.y());

  gtk_window_move(GTK_WINDOW(container_), x, y);
}

void DraggedTabGtk::Attach(int selected_width) {
  attached_ = true;
  Resize(selected_width);

  if (gtk_util::IsScreenComposited())
    gdk_window_set_opacity(container_->window, kOpaqueAlpha);
}

void DraggedTabGtk::Resize(int width) {
  attached_tab_size_.set_width(width);
  ResizeContainer();
}

void DraggedTabGtk::set_pinned(bool pinned) {
  renderer_->set_pinned(pinned);
}

bool DraggedTabGtk::is_pinned() const {
  return renderer_->is_pinned();
}

void DraggedTabGtk::Detach(GtkWidget* contents, BackingStore* backing_store) {
  // Detached tabs are never pinned.
  renderer_->set_pinned(false);

  if (attached_tab_size_.width() != tab_width_) {
    // The attached tab size differs from current tab size. Resize accordingly.
    Resize(tab_width_);
  }

  attached_ = false;
  contents_ = contents;
  backing_store_ = backing_store;
  ResizeContainer();

  if (gtk_util::IsScreenComposited())
    gdk_window_set_opacity(container_->window, kTransparentAlpha);
}

void DraggedTabGtk::Update() {
  gtk_widget_queue_draw(container_);
}

void DraggedTabGtk::AnimateToBounds(const gfx::Rect& bounds,
                                    AnimateToBoundsCallback* callback) {
  animation_callback_.reset(callback);

  gint x, y, width, height;
  gdk_window_get_origin(container_->window, &x, &y);
  gdk_window_get_geometry(container_->window, NULL, NULL,
                          &width, &height, NULL);

  animation_start_bounds_ = gfx::Rect(x, y, width, height);
  animation_end_bounds_ = bounds;

  close_animation_.SetSlideDuration(kAnimateToBoundsDurationMs);
  close_animation_.SetTweenType(SlideAnimation::EASE_OUT);
  if (!close_animation_.IsShowing()) {
    close_animation_.Reset();
    close_animation_.Show();
  }
}

////////////////////////////////////////////////////////////////////////////////
// DraggedTabGtk, AnimationDelegate implementation:

void DraggedTabGtk::AnimationProgressed(const Animation* animation) {
  int delta_x = (animation_end_bounds_.x() - animation_start_bounds_.x());
  int x = animation_start_bounds_.x() +
      static_cast<int>(delta_x * animation->GetCurrentValue());
  int y = animation_end_bounds_.y();
  gdk_window_move(container_->window, x, y);
}

void DraggedTabGtk::AnimationEnded(const Animation* animation) {
  animation_callback_->Run();
}

void DraggedTabGtk::AnimationCanceled(const Animation* animation) {
  AnimationEnded(animation);
}

////////////////////////////////////////////////////////////////////////////////
// DraggedTabGtk, private:

void DraggedTabGtk::Layout() {
  if (attached_) {
    gfx::Size prefsize = GetPreferredSize();
    renderer_->SetBounds(gfx::Rect(0, 0, prefsize.width(), prefsize.height()));
  } else {
    int left = 0;
    if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT)
      left = GetPreferredSize().width() - attached_tab_size_.width();

    // The renderer_'s width should be attached_tab_size_.width() in both LTR
    // and RTL locales. Wrong width will cause the wrong positioning of the tab
    // view in dragging. Please refer to http://crbug.com/6223 for details.
    renderer_->SetBounds(gfx::Rect(left, 0, attached_tab_size_.width(),
                         attached_tab_size_.height()));
  }
}

gfx::Size DraggedTabGtk::GetPreferredSize() {
  if (attached_)
    return attached_tab_size_;

  int width = std::max(attached_tab_size_.width(), contents_size_.width()) +
      kTwiceDragFrameBorderSize;
  int height = attached_tab_size_.height() + kDragFrameBorderSize +
      contents_size_.height();
  return gfx::Size(width, height);
}

void DraggedTabGtk::ResizeContainer() {
  gfx::Size size = GetPreferredSize();
  gtk_window_resize(GTK_WINDOW(container_),
                    ScaleValue(size.width()), ScaleValue(size.height()));
  Layout();
}

int DraggedTabGtk::ScaleValue(int value) {
  return attached_ ? value : static_cast<int>(value * kScalingFactor);
}

gfx::Rect DraggedTabGtk::bounds() const {
  gint x, y, width, height;
  gtk_window_get_position(GTK_WINDOW(container_), &x, &y);
  gtk_window_get_size(GTK_WINDOW(container_), &width, &height);
  return gfx::Rect(x, y, width, height);
}

void DraggedTabGtk::SetContainerColorMap() {
  GdkScreen* screen = gtk_widget_get_screen(container_);
  GdkColormap* colormap = gdk_screen_get_rgba_colormap(screen);

  // If rgba is not available, use rgb instead.
  if (!colormap)
    colormap = gdk_screen_get_rgb_colormap(screen);

  gtk_widget_set_colormap(container_, colormap);
}

void DraggedTabGtk::SetContainerTransparency() {
  cairo_t* cairo_context = gdk_cairo_create(container_->window);
  if (!cairo_context)
    return;

  // Make the background of the dragged tab window fully transparent.  All of
  // the content of the window (child widgets) will be completely opaque.
  gfx::Size size = bounds().size();
  cairo_scale(cairo_context, static_cast<double>(size.width()),
              static_cast<double>(size.height()));
  cairo_set_source_rgba(cairo_context, 1.0f, 1.0f, 1.0f, 0.0f);
  cairo_set_operator(cairo_context, CAIRO_OPERATOR_SOURCE);
  cairo_paint(cairo_context);
  cairo_destroy(cairo_context);
}

void DraggedTabGtk::SetContainerShapeMask(GdkPixbuf* pixbuf) {
  // Create a 1bpp bitmap the size of |container_|.
  gfx::Size size = bounds().size();
  GdkPixmap* pixmap = gdk_pixmap_new(NULL, size.width(), size.height(), 1);
  cairo_t* cairo_context = gdk_cairo_create(GDK_DRAWABLE(pixmap));

  // Set the transparency.
  cairo_set_source_rgba(cairo_context, 1.0f, 1.0f, 1.0f, 0.0f);

  // Blit the rendered bitmap into a pixmap.  Any pixel set in the pixmap will
  // be opaque in the container window.
  cairo_set_operator(cairo_context, CAIRO_OPERATOR_SOURCE);
  if (!attached_)
    cairo_scale(cairo_context, kScalingFactor, kScalingFactor);
  gdk_cairo_set_source_pixbuf(cairo_context, pixbuf, 0, 0);
  cairo_paint(cairo_context);

  if (!attached_) {
    // Make the render area depiction opaque (leaving enough room for the
    // border).
    cairo_identity_matrix(cairo_context);
    cairo_set_source_rgba(cairo_context, 1.0f, 1.0f, 1.0f, 1.0f);
    int tab_height = kScalingFactor * gdk_pixbuf_get_height(pixbuf) -
                     kDragFrameBorderSize;
    cairo_rectangle(cairo_context,
                    0, tab_height,
                    size.width(), size.height() - tab_height);
    cairo_fill(cairo_context);
  }

  cairo_destroy(cairo_context);

  // Set the shape mask.
  gdk_window_shape_combine_mask(container_->window, pixmap, 0, 0);
  g_object_unref(pixmap);
}

GdkPixbuf* DraggedTabGtk::PaintTab() {
  SkBitmap bitmap = renderer_->PaintBitmap();
  return gfx::GdkPixbufFromSkBitmap(&bitmap);
}

// static
gboolean DraggedTabGtk::OnExposeEvent(GtkWidget* widget,
                                      GdkEventExpose* event,
                                      DraggedTabGtk* dragged_tab) {
  GdkPixbuf* pixbuf = dragged_tab->PaintTab();
  if (gtk_util::IsScreenComposited()) {
    dragged_tab->SetContainerTransparency();
  } else {
    dragged_tab->SetContainerShapeMask(pixbuf);
  }

  // Only used when not attached.
  int tab_height = kScalingFactor * gdk_pixbuf_get_height(pixbuf);
  int tab_width = kScalingFactor * gdk_pixbuf_get_width(pixbuf);

  // Draw the render area.
  if (dragged_tab->backing_store_ && !dragged_tab->attached_) {
    // This leaves room for the border.
    dragged_tab->backing_store_->PaintToRect(
        gfx::Rect(kDragFrameBorderSize, tab_height,
                  widget->allocation.width - kTwiceDragFrameBorderSize,
                  widget->allocation.height - tab_height -
                  kDragFrameBorderSize),
        GDK_DRAWABLE(widget->window));
  }

  cairo_t* cr = gdk_cairo_create(GDK_DRAWABLE(widget->window));
  // Draw the border.
  if (!dragged_tab->attached_) {
    cairo_set_line_width(cr, kDragFrameBorderSize);
    cairo_set_source_rgb(cr, kDraggedTabBorderColor[0],
                             kDraggedTabBorderColor[1],
                             kDraggedTabBorderColor[2]);
    // |offset| is the distance from the edge of the image to the middle of
    // the border line.
    double offset = kDragFrameBorderSize / 2.0 - 0.5;
    double left_x = offset;
    double top_y = tab_height - kDragFrameBorderSize + offset;
    double right_x = widget->allocation.width - offset;
    double bottom_y = widget->allocation.height - offset;
    double middle_x = tab_width + offset;

    // We don't use cairo_rectangle() because we don't want to draw the border
    // under the tab itself.
    cairo_move_to(cr, left_x, top_y);
    cairo_line_to(cr, left_x, bottom_y);
    cairo_line_to(cr, right_x, bottom_y);
    cairo_line_to(cr, right_x, top_y);
    cairo_line_to(cr, middle_x, top_y);
    cairo_stroke(cr);
  }

  // Draw the tab.
  if (!dragged_tab->attached_)
    cairo_scale(cr, kScalingFactor, kScalingFactor);
  gdk_cairo_set_source_pixbuf(cr, pixbuf, 0, 0);
  cairo_paint(cr);

  cairo_destroy(cr);

  g_object_unref(pixbuf);

  // We've already drawn the tab, so don't propagate the expose-event signal.
  return TRUE;
}
<|endoftext|>


<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 "chrome/browser/tabs/default_tab_handler.h"
#include "chrome/browser/tabs/tab_strip_model.h"
#include "chrome/browser/ui/browser.h"

////////////////////////////////////////////////////////////////////////////////
// DefaultTabHandler, public:

DefaultTabHandler::DefaultTabHandler(TabHandlerDelegate* delegate)
    : delegate_(delegate),
      ALLOW_THIS_IN_INITIALIZER_LIST(
          model_(new TabStripModel(this, delegate->GetProfile()))) {
  model_->AddObserver(this);
}

DefaultTabHandler::~DefaultTabHandler() {
  // The tab strip should not have any tabs at this point.
  DCHECK(model_->empty());
  model_->RemoveObserver(this);
}

////////////////////////////////////////////////////////////////////////////////
// DefaultTabHandler, TabHandler implementation:

TabStripModel* DefaultTabHandler::GetTabStripModel() const {
  return model_.get();
}

////////////////////////////////////////////////////////////////////////////////
// DefaultTabHandler, TabStripModelDelegate implementation:

TabContentsWrapper* DefaultTabHandler::AddBlankTab(bool foreground) {
  return delegate_->AsBrowser()->AddBlankTab(foreground);
}

TabContentsWrapper* DefaultTabHandler::AddBlankTabAt(int index,
                                                     bool foreground) {
  return delegate_->AsBrowser()->AddBlankTabAt(index, foreground);
}

Browser* DefaultTabHandler::CreateNewStripWithContents(
    TabContentsWrapper* detached_contents,
    const gfx::Rect& window_bounds,
    const DockInfo& dock_info,
    bool maximize) {
  return delegate_->AsBrowser()->CreateNewStripWithContents(detached_contents,
                                                            window_bounds,
                                                            dock_info,
                                                            maximize);
}

int DefaultTabHandler::GetDragActions() const {
  return delegate_->AsBrowser()->GetDragActions();
}

TabContentsWrapper* DefaultTabHandler::CreateTabContentsForURL(
    const GURL& url,
    const content::Referrer& referrer,
    Profile* profile,
    content::PageTransition transition,
    bool defer_load,
    SiteInstance* instance) const {
  return delegate_->AsBrowser()->CreateTabContentsForURL(url,
                                                         referrer,
                                                         profile,
                                                         transition,
                                                         defer_load,
                                                         instance);
}

bool DefaultTabHandler::CanDuplicateContentsAt(int index) {
  return delegate_->AsBrowser()->CanDuplicateContentsAt(index);
}

void DefaultTabHandler::DuplicateContentsAt(int index) {
  delegate_->AsBrowser()->DuplicateContentsAt(index);
}

void DefaultTabHandler::CloseFrameAfterDragSession() {
  delegate_->AsBrowser()->CloseFrameAfterDragSession();
}

void DefaultTabHandler::CreateHistoricalTab(TabContentsWrapper* contents) {
  delegate_->AsBrowser()->CreateHistoricalTab(contents);
}

bool DefaultTabHandler::RunUnloadListenerBeforeClosing(
    TabContentsWrapper* contents) {
  return delegate_->AsBrowser()->RunUnloadListenerBeforeClosing(contents);
}

bool DefaultTabHandler::CanCloseContents(std::vector<int>* indices) {
  return delegate_->AsBrowser()->CanCloseContents(indices);
}

bool DefaultTabHandler::CanBookmarkAllTabs() const {
  return delegate_->AsBrowser()->CanBookmarkAllTabs();
}

void DefaultTabHandler::BookmarkAllTabs() {
  delegate_->AsBrowser()->BookmarkAllTabs();
}

bool DefaultTabHandler::CanCloseTab() const {
  return delegate_->AsBrowser()->CanCloseTab();
}

bool DefaultTabHandler::CanRestoreTab() {
  return delegate_->AsBrowser()->CanRestoreTab();
}

void DefaultTabHandler::RestoreTab() {
  delegate_->AsBrowser()->RestoreTab();
}

bool DefaultTabHandler::LargeIconsPermitted() const {
  return delegate_->AsBrowser()->LargeIconsPermitted();
}

////////////////////////////////////////////////////////////////////////////////
// DefaultTabHandler, TabStripModelObserver implementation:

void DefaultTabHandler::TabInsertedAt(TabContentsWrapper* contents,
                                      int index,
                                      bool foreground) {
  delegate_->AsBrowser()->TabInsertedAt(contents, index, foreground);
}

void DefaultTabHandler::TabClosingAt(TabStripModel* tab_strip_model,
                                     TabContentsWrapper* contents,
                                     int index) {
  delegate_->AsBrowser()->TabClosingAt(tab_strip_model, contents, index);
}

void DefaultTabHandler::TabDetachedAt(TabContentsWrapper* contents, int index) {
  delegate_->AsBrowser()->TabDetachedAt(contents, index);
}

void DefaultTabHandler::TabDeactivated(TabContentsWrapper* contents) {
  delegate_->AsBrowser()->TabDeactivated(contents);
}

void DefaultTabHandler::ActiveTabChanged(TabContentsWrapper* old_contents,
                                         TabContentsWrapper* new_contents,
                                         int index,
                                         bool user_gesture) {
  delegate_->AsBrowser()->ActiveTabChanged(old_contents,
                                           new_contents,
                                           index,
                                           user_gesture);
}

void DefaultTabHandler::TabMoved(TabContentsWrapper* contents,
                                 int from_index,
                                 int to_index) {
  delegate_->AsBrowser()->TabMoved(contents, from_index, to_index);
}

void DefaultTabHandler::TabReplacedAt(TabStripModel* tab_strip_model,
                                      TabContentsWrapper* old_contents,
                                      TabContentsWrapper* new_contents,
                                      int index) {
  delegate_->AsBrowser()->TabReplacedAt(tab_strip_model, old_contents,
                                        new_contents, index);
}

void DefaultTabHandler::TabPinnedStateChanged(TabContentsWrapper* contents,
                                              int index) {
  delegate_->AsBrowser()->TabPinnedStateChanged(contents, index);
}

void DefaultTabHandler::TabStripEmpty() {
  delegate_->AsBrowser()->TabStripEmpty();
}

////////////////////////////////////////////////////////////////////////////////
// TabHandler, public:

// static
TabHandler* TabHandler::CreateTabHandler(TabHandlerDelegate* delegate) {
  return new DefaultTabHandler(delegate);
}
<commit_msg>Bug repro 1) Build aura desktop for desktop (not ChromeOS) 2) Close aura desktop using (x) on Aura Desktop, not in any of the aura windows<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 "chrome/browser/browser_shutdown.h"
#include "chrome/browser/tabs/default_tab_handler.h"
#include "chrome/browser/tabs/tab_strip_model.h"
#include "chrome/browser/ui/browser.h"

////////////////////////////////////////////////////////////////////////////////
// DefaultTabHandler, public:

DefaultTabHandler::DefaultTabHandler(TabHandlerDelegate* delegate)
    : delegate_(delegate),
      ALLOW_THIS_IN_INITIALIZER_LIST(
          model_(new TabStripModel(this, delegate->GetProfile()))) {
  model_->AddObserver(this);
}

DefaultTabHandler::~DefaultTabHandler() {
  // The tab strip should not have any tabs at this point.
  if (!browser_shutdown::ShuttingDownWithoutClosingBrowsers())
    DCHECK(model_->empty());
  model_->RemoveObserver(this);
}

////////////////////////////////////////////////////////////////////////////////
// DefaultTabHandler, TabHandler implementation:

TabStripModel* DefaultTabHandler::GetTabStripModel() const {
  return model_.get();
}

////////////////////////////////////////////////////////////////////////////////
// DefaultTabHandler, TabStripModelDelegate implementation:

TabContentsWrapper* DefaultTabHandler::AddBlankTab(bool foreground) {
  return delegate_->AsBrowser()->AddBlankTab(foreground);
}

TabContentsWrapper* DefaultTabHandler::AddBlankTabAt(int index,
                                                     bool foreground) {
  return delegate_->AsBrowser()->AddBlankTabAt(index, foreground);
}

Browser* DefaultTabHandler::CreateNewStripWithContents(
    TabContentsWrapper* detached_contents,
    const gfx::Rect& window_bounds,
    const DockInfo& dock_info,
    bool maximize) {
  return delegate_->AsBrowser()->CreateNewStripWithContents(detached_contents,
                                                            window_bounds,
                                                            dock_info,
                                                            maximize);
}

int DefaultTabHandler::GetDragActions() const {
  return delegate_->AsBrowser()->GetDragActions();
}

TabContentsWrapper* DefaultTabHandler::CreateTabContentsForURL(
    const GURL& url,
    const content::Referrer& referrer,
    Profile* profile,
    content::PageTransition transition,
    bool defer_load,
    SiteInstance* instance) const {
  return delegate_->AsBrowser()->CreateTabContentsForURL(url,
                                                         referrer,
                                                         profile,
                                                         transition,
                                                         defer_load,
                                                         instance);
}

bool DefaultTabHandler::CanDuplicateContentsAt(int index) {
  return delegate_->AsBrowser()->CanDuplicateContentsAt(index);
}

void DefaultTabHandler::DuplicateContentsAt(int index) {
  delegate_->AsBrowser()->DuplicateContentsAt(index);
}

void DefaultTabHandler::CloseFrameAfterDragSession() {
  delegate_->AsBrowser()->CloseFrameAfterDragSession();
}

void DefaultTabHandler::CreateHistoricalTab(TabContentsWrapper* contents) {
  delegate_->AsBrowser()->CreateHistoricalTab(contents);
}

bool DefaultTabHandler::RunUnloadListenerBeforeClosing(
    TabContentsWrapper* contents) {
  return delegate_->AsBrowser()->RunUnloadListenerBeforeClosing(contents);
}

bool DefaultTabHandler::CanCloseContents(std::vector<int>* indices) {
  return delegate_->AsBrowser()->CanCloseContents(indices);
}

bool DefaultTabHandler::CanBookmarkAllTabs() const {
  return delegate_->AsBrowser()->CanBookmarkAllTabs();
}

void DefaultTabHandler::BookmarkAllTabs() {
  delegate_->AsBrowser()->BookmarkAllTabs();
}

bool DefaultTabHandler::CanCloseTab() const {
  return delegate_->AsBrowser()->CanCloseTab();
}

bool DefaultTabHandler::CanRestoreTab() {
  return delegate_->AsBrowser()->CanRestoreTab();
}

void DefaultTabHandler::RestoreTab() {
  delegate_->AsBrowser()->RestoreTab();
}

bool DefaultTabHandler::LargeIconsPermitted() const {
  return delegate_->AsBrowser()->LargeIconsPermitted();
}

////////////////////////////////////////////////////////////////////////////////
// DefaultTabHandler, TabStripModelObserver implementation:

void DefaultTabHandler::TabInsertedAt(TabContentsWrapper* contents,
                                      int index,
                                      bool foreground) {
  delegate_->AsBrowser()->TabInsertedAt(contents, index, foreground);
}

void DefaultTabHandler::TabClosingAt(TabStripModel* tab_strip_model,
                                     TabContentsWrapper* contents,
                                     int index) {
  delegate_->AsBrowser()->TabClosingAt(tab_strip_model, contents, index);
}

void DefaultTabHandler::TabDetachedAt(TabContentsWrapper* contents, int index) {
  delegate_->AsBrowser()->TabDetachedAt(contents, index);
}

void DefaultTabHandler::TabDeactivated(TabContentsWrapper* contents) {
  delegate_->AsBrowser()->TabDeactivated(contents);
}

void DefaultTabHandler::ActiveTabChanged(TabContentsWrapper* old_contents,
                                         TabContentsWrapper* new_contents,
                                         int index,
                                         bool user_gesture) {
  delegate_->AsBrowser()->ActiveTabChanged(old_contents,
                                           new_contents,
                                           index,
                                           user_gesture);
}

void DefaultTabHandler::TabMoved(TabContentsWrapper* contents,
                                 int from_index,
                                 int to_index) {
  delegate_->AsBrowser()->TabMoved(contents, from_index, to_index);
}

void DefaultTabHandler::TabReplacedAt(TabStripModel* tab_strip_model,
                                      TabContentsWrapper* old_contents,
                                      TabContentsWrapper* new_contents,
                                      int index) {
  delegate_->AsBrowser()->TabReplacedAt(tab_strip_model, old_contents,
                                        new_contents, index);
}

void DefaultTabHandler::TabPinnedStateChanged(TabContentsWrapper* contents,
                                              int index) {
  delegate_->AsBrowser()->TabPinnedStateChanged(contents, index);
}

void DefaultTabHandler::TabStripEmpty() {
  delegate_->AsBrowser()->TabStripEmpty();
}

////////////////////////////////////////////////////////////////////////////////
// TabHandler, public:

// static
TabHandler* TabHandler::CreateTabHandler(TabHandlerDelegate* delegate) {
  return new DefaultTabHandler(delegate);
}
<|endoftext|>


<commit_before>// Copyright (c) 2012 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 "chrome/browser/ui/webui/version_handler.h"

#include "base/command_line.h"
#include "base/file_util.h"
#include "base/metrics/field_trial.h"
#include "base/string_split.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/plugins/plugin_prefs.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/metrics/variations/variations_util.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/plugin_service.h"
#include "content/public/browser/web_ui.h"
#include "googleurl/src/gurl.h"
#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
#include "webkit/plugins/plugin_constants.h"

namespace {

// Retrieves the executable and profile paths on the FILE thread.
void GetFilePaths(const FilePath& profile_path,
                  string16* exec_path_out,
                  string16* profile_path_out) {
  DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));

  FilePath executable_path = CommandLine::ForCurrentProcess()->GetProgram();
  if (file_util::AbsolutePath(&executable_path)) {
    *exec_path_out = executable_path.LossyDisplayName();
  } else {
    *exec_path_out =
        l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_PATH_NOTFOUND);
  }

  FilePath profile_path_copy(profile_path);
  if (!profile_path.empty() && file_util::AbsolutePath(&profile_path_copy)) {
    *profile_path_out = profile_path.LossyDisplayName();
  } else {
    *profile_path_out =
        l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_PATH_NOTFOUND);
  }
}

}  // namespace

VersionHandler::VersionHandler()
    : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
}

VersionHandler::~VersionHandler() {
}

void VersionHandler::RegisterMessages() {
  web_ui()->RegisterMessageCallback(
      "requestVersionInfo",
      base::Bind(&VersionHandler::HandleRequestVersionInfo,
      base::Unretained(this)));
}

void VersionHandler::HandleRequestVersionInfo(const ListValue* args) {
  // The Flash version information is needed in the response, so make sure
  // the plugins are loaded.
  content::PluginService::GetInstance()->GetPlugins(
      base::Bind(&VersionHandler::OnGotPlugins,
          weak_ptr_factory_.GetWeakPtr()));

  // Grab the executable path on the FILE thread. It is returned in
  // OnGotFilePaths.
  string16* exec_path_buffer = new string16;
  string16* profile_path_buffer = new string16;
  content::BrowserThread::PostTaskAndReply(
      content::BrowserThread::FILE, FROM_HERE,
          base::Bind(&GetFilePaths, Profile::FromWebUI(web_ui())->GetPath(),
                     base::Unretained(exec_path_buffer),
                     base::Unretained(profile_path_buffer)),
          base::Bind(&VersionHandler::OnGotFilePaths,
                     weak_ptr_factory_.GetWeakPtr(),
                     base::Owned(exec_path_buffer),
                     base::Owned(profile_path_buffer)));

  // Respond with the variations info immediately.
  scoped_ptr<ListValue> variations_list(new ListValue());
  std::vector<std::string> variations;
#if !defined(NDEBUG)
  std::string variation_state;
  base::FieldTrialList::StatesToString(&variation_state);

  std::vector<std::string> tokens;
  base::SplitString(variation_state,
                    base::FieldTrialList::kPersistentStringSeparator,
                    &tokens);
  // Since StatesToString appends a separator at the end, SplitString will
  // append an extra empty string in the vector. Drop it. There should
  // always be an even number of tokens left.
  tokens.pop_back();
  DCHECK_EQ(0U, tokens.size() % 2);
  for (size_t i = 0; i < tokens.size(); i += 2)
    variations.push_back(tokens[i] + ":" + tokens[i + 1]);
#else
  // In release mode, display the hashes only.
  std::vector<string16> selected_groups;
  chrome_variations::GetFieldTrialSelectedGroupIdsAsStrings(&selected_groups);
  for (size_t i = 0; i < selected_groups.size(); ++i)
    variations.push_back(UTF16ToASCII(selected_groups[i]));
#endif

  for (std::vector<std::string>::const_iterator it = variations.begin();
      it != variations.end(); ++it) {
    variations_list->Append(Value::CreateStringValue(*it));
  }

  // In release mode, this will return an empty list to clear the section.
  web_ui()->CallJavascriptFunction("returnVariationInfo",
                                   *variations_list.release());
}

void VersionHandler::OnGotFilePaths(string16* executable_path_data,
                                    string16* profile_path_data) {
  DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));

  StringValue exec_path(*executable_path_data);
  StringValue profile_path(*profile_path_data);
  web_ui()->CallJavascriptFunction("returnFilePaths", exec_path, profile_path);
}

void VersionHandler::OnGotPlugins(
    const std::vector<webkit::WebPluginInfo>& plugins) {
#if !defined(OS_ANDROID)
  // Obtain the version of the first enabled Flash plugin.
  std::vector<webkit::WebPluginInfo> info_array;
  content::PluginService::GetInstance()->GetPluginInfoArray(
      GURL(), kFlashPluginSwfMimeType, false, &info_array, NULL);
  string16 flash_version =
      l10n_util::GetStringUTF16(IDS_PLUGINS_DISABLED_PLUGIN);
  PluginPrefs* plugin_prefs =
      PluginPrefs::GetForProfile(Profile::FromWebUI(web_ui()));
  if (plugin_prefs) {
    for (size_t i = 0; i < info_array.size(); ++i) {
      if (plugin_prefs->IsPluginEnabled(info_array[i])) {
        flash_version = info_array[i].version;
        break;
      }
    }
  }

  StringValue arg(flash_version);
  web_ui()->CallJavascriptFunction("returnFlashVersion", arg);
#endif
}
<commit_msg>Use a non-breaking hyphen for chrome://versions variations list.<commit_after>// Copyright (c) 2012 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 "chrome/browser/ui/webui/version_handler.h"

#include "base/command_line.h"
#include "base/file_util.h"
#include "base/metrics/field_trial.h"
#include "base/string_split.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/plugins/plugin_prefs.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/metrics/variations/variations_util.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/plugin_service.h"
#include "content/public/browser/web_ui.h"
#include "googleurl/src/gurl.h"
#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
#include "webkit/plugins/plugin_constants.h"

namespace {

// Retrieves the executable and profile paths on the FILE thread.
void GetFilePaths(const FilePath& profile_path,
                  string16* exec_path_out,
                  string16* profile_path_out) {
  DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));

  FilePath executable_path = CommandLine::ForCurrentProcess()->GetProgram();
  if (file_util::AbsolutePath(&executable_path)) {
    *exec_path_out = executable_path.LossyDisplayName();
  } else {
    *exec_path_out =
        l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_PATH_NOTFOUND);
  }

  FilePath profile_path_copy(profile_path);
  if (!profile_path.empty() && file_util::AbsolutePath(&profile_path_copy)) {
    *profile_path_out = profile_path.LossyDisplayName();
  } else {
    *profile_path_out =
        l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_PATH_NOTFOUND);
  }
}

}  // namespace

VersionHandler::VersionHandler()
    : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
}

VersionHandler::~VersionHandler() {
}

void VersionHandler::RegisterMessages() {
  web_ui()->RegisterMessageCallback(
      "requestVersionInfo",
      base::Bind(&VersionHandler::HandleRequestVersionInfo,
      base::Unretained(this)));
}

void VersionHandler::HandleRequestVersionInfo(const ListValue* args) {
  // The Flash version information is needed in the response, so make sure
  // the plugins are loaded.
  content::PluginService::GetInstance()->GetPlugins(
      base::Bind(&VersionHandler::OnGotPlugins,
          weak_ptr_factory_.GetWeakPtr()));

  // Grab the executable path on the FILE thread. It is returned in
  // OnGotFilePaths.
  string16* exec_path_buffer = new string16;
  string16* profile_path_buffer = new string16;
  content::BrowserThread::PostTaskAndReply(
      content::BrowserThread::FILE, FROM_HERE,
          base::Bind(&GetFilePaths, Profile::FromWebUI(web_ui())->GetPath(),
                     base::Unretained(exec_path_buffer),
                     base::Unretained(profile_path_buffer)),
          base::Bind(&VersionHandler::OnGotFilePaths,
                     weak_ptr_factory_.GetWeakPtr(),
                     base::Owned(exec_path_buffer),
                     base::Owned(profile_path_buffer)));

  // Respond with the variations info immediately.
  scoped_ptr<ListValue> variations_list(new ListValue());
  std::vector<std::string> variations;
#if !defined(NDEBUG)
  std::string variation_state;
  base::FieldTrialList::StatesToString(&variation_state);

  std::vector<std::string> tokens;
  base::SplitString(variation_state,
                    base::FieldTrialList::kPersistentStringSeparator,
                    &tokens);
  // Since StatesToString appends a separator at the end, SplitString will
  // append an extra empty string in the vector. Drop it. There should
  // always be an even number of tokens left.
  tokens.pop_back();
  DCHECK_EQ(0U, tokens.size() % 2);
  const unsigned char kNonBreakingHyphenUTF8[] = { 0xE2, 0x80, 0x91, '\0' };
  const std::string kNonBreakingHyphenUTF8String(
      reinterpret_cast<const char*>(kNonBreakingHyphenUTF8));
  for (size_t i = 0; i < tokens.size(); i += 2) {
    std::string line = tokens[i] + ":" + tokens[i + 1];
    ReplaceChars(line, "-", kNonBreakingHyphenUTF8String, &line);
    variations.push_back(line);
  }
#else
  // In release mode, display the hashes only.
  std::vector<string16> selected_groups;
  chrome_variations::GetFieldTrialSelectedGroupIdsAsStrings(&selected_groups);
  for (size_t i = 0; i < selected_groups.size(); ++i)
    variations.push_back(UTF16ToASCII(selected_groups[i]));
#endif

  for (std::vector<std::string>::const_iterator it = variations.begin();
      it != variations.end(); ++it) {
    variations_list->Append(Value::CreateStringValue(*it));
  }

  // In release mode, this will return an empty list to clear the section.
  web_ui()->CallJavascriptFunction("returnVariationInfo",
                                   *variations_list.release());
}

void VersionHandler::OnGotFilePaths(string16* executable_path_data,
                                    string16* profile_path_data) {
  DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));

  StringValue exec_path(*executable_path_data);
  StringValue profile_path(*profile_path_data);
  web_ui()->CallJavascriptFunction("returnFilePaths", exec_path, profile_path);
}

void VersionHandler::OnGotPlugins(
    const std::vector<webkit::WebPluginInfo>& plugins) {
#if !defined(OS_ANDROID)
  // Obtain the version of the first enabled Flash plugin.
  std::vector<webkit::WebPluginInfo> info_array;
  content::PluginService::GetInstance()->GetPluginInfoArray(
      GURL(), kFlashPluginSwfMimeType, false, &info_array, NULL);
  string16 flash_version =
      l10n_util::GetStringUTF16(IDS_PLUGINS_DISABLED_PLUGIN);
  PluginPrefs* plugin_prefs =
      PluginPrefs::GetForProfile(Profile::FromWebUI(web_ui()));
  if (plugin_prefs) {
    for (size_t i = 0; i < info_array.size(); ++i) {
      if (plugin_prefs->IsPluginEnabled(info_array[i])) {
        flash_version = info_array[i].version;
        break;
      }
    }
  }

  StringValue arg(flash_version);
  web_ui()->CallJavascriptFunction("returnFlashVersion", arg);
#endif
}
<|endoftext|>


<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 "chrome/browser/favicon/favicon_tab_helper.h"
#include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h"
#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
#include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h"
#include "chrome/common/url_constants.h"
#include "chrome/test/base/testing_profile.h"
#include "content/browser/browser_thread.h"
#include "content/browser/site_instance.h"
#include "content/browser/tab_contents/navigation_controller.h"
#include "content/browser/tab_contents/test_tab_contents.h"
#include "testing/gtest/include/gtest/gtest.h"

class WebUITest : public TabContentsWrapperTestHarness {
 public:
  WebUITest() : ui_thread_(BrowserThread::UI, MessageLoop::current()) {}

  // Tests navigating with a Web UI from a fresh (nothing pending or committed)
  // state, through pending, committed, then another navigation. The first page
  // ID that we should use is passed as a parameter. We'll use the next two
  // values. This must be increasing for the life of the tests.
  static void DoNavigationTest(TabContentsWrapper* wrapper, int page_id) {
    TabContents* contents = wrapper->tab_contents();
    NavigationController* controller = &contents->controller();

    // Start a pending load.
    GURL new_tab_url(chrome::kChromeUINewTabURL);
    controller->LoadURL(new_tab_url, GURL(), PageTransition::LINK);

    // The navigation entry should be pending with no committed entry.
    ASSERT_TRUE(controller->pending_entry());
    ASSERT_FALSE(controller->GetLastCommittedEntry());

    // Check the things the pending Web UI should have set.
    EXPECT_FALSE(contents->ShouldDisplayURL());
    EXPECT_FALSE(wrapper->favicon_tab_helper()->ShouldDisplayFavicon());
    EXPECT_TRUE(wrapper->bookmark_tab_helper()->ShouldShowBookmarkBar());
    EXPECT_TRUE(contents->FocusLocationBarByDefault());

    // Now commit the load.
    static_cast<TestRenderViewHost*>(
        contents->render_view_host())->SendNavigate(page_id, new_tab_url);

    // The same flags should be set as before now that the load has committed.
    EXPECT_FALSE(contents->ShouldDisplayURL());
    EXPECT_FALSE(wrapper->favicon_tab_helper()->ShouldDisplayFavicon());
    EXPECT_TRUE(wrapper->bookmark_tab_helper()->ShouldShowBookmarkBar());
    EXPECT_TRUE(contents->FocusLocationBarByDefault());

    // Start a pending navigation to a regular page.
    GURL next_url("http://google.com/");
    controller->LoadURL(next_url, GURL(), PageTransition::LINK);

    // Check the flags. Some should reflect the new page (URL, title), some
    // should reflect the old one (bookmark bar) until it has committed.
    EXPECT_TRUE(contents->ShouldDisplayURL());
    EXPECT_TRUE(wrapper->favicon_tab_helper()->ShouldDisplayFavicon());
    EXPECT_TRUE(wrapper->bookmark_tab_helper()->ShouldShowBookmarkBar());
    EXPECT_FALSE(contents->FocusLocationBarByDefault());

    // Commit the regular page load. Note that we must send it to the "pending"
    // RenderViewHost if there is one, since this transition will also cause a
    // process transition, and our RVH pointer will be the "committed" one.
    // In the second call to this function from WebUIToStandard, it won't
    // actually be pending, which is the point of this test.
    if (contents->render_manager()->pending_render_view_host()) {
      static_cast<TestRenderViewHost*>(
          contents->render_manager()->pending_render_view_host())->SendNavigate(
              page_id + 1, next_url);
    } else {
      static_cast<TestRenderViewHost*>(
          contents->render_view_host())->SendNavigate(page_id + 1, next_url);
    }

    // The state should now reflect a regular page.
    EXPECT_TRUE(contents->ShouldDisplayURL());
    EXPECT_TRUE(wrapper->favicon_tab_helper()->ShouldDisplayFavicon());
    EXPECT_FALSE(wrapper->bookmark_tab_helper()->ShouldShowBookmarkBar());
    EXPECT_FALSE(contents->FocusLocationBarByDefault());
  }

 private:
  BrowserThread ui_thread_;

  DISALLOW_COPY_AND_ASSIGN(WebUITest);
};

// Tests that the New Tab Page flags are correctly set and propogated by
// TabContents when we first navigate to a Web UI page, then to a standard
// non-DOM-UI page.
TEST_F(WebUITest, WebUIToStandard) {
  DoNavigationTest(contents_wrapper(), 1);

  // Test the case where we're not doing the initial navigation. This is
  // slightly different than the very-first-navigation case since the
  // SiteInstance will be the same (the original TabContents must still be
  // alive), which will trigger different behavior in RenderViewHostManager.
  TestTabContents* contents2 = new TestTabContents(profile_.get(), NULL);
  TabContentsWrapper wrapper2(contents2);

  DoNavigationTest(&wrapper2, 101);
}

TEST_F(WebUITest, WebUIToWebUI) {
  // Do a load (this state is tested above).
  GURL new_tab_url(chrome::kChromeUINewTabURL);
  controller().LoadURL(new_tab_url, GURL(), PageTransition::LINK);
  rvh()->SendNavigate(1, new_tab_url);

  // Start another pending load of the new tab page.
  controller().LoadURL(new_tab_url, GURL(), PageTransition::LINK);
  rvh()->SendNavigate(2, new_tab_url);

  // The flags should be the same as the non-pending state.
  EXPECT_FALSE(contents()->ShouldDisplayURL());
  EXPECT_FALSE(
      contents_wrapper()->favicon_tab_helper()->ShouldDisplayFavicon());
  EXPECT_TRUE(
      contents_wrapper()->bookmark_tab_helper()->ShouldShowBookmarkBar());
  EXPECT_TRUE(contents()->FocusLocationBarByDefault());
}

TEST_F(WebUITest, StandardToWebUI) {
  // Start a pending navigation to a regular page.
  GURL std_url("http://google.com/");

  controller().LoadURL(std_url, GURL(), PageTransition::LINK);

  // The state should now reflect the default.
  EXPECT_TRUE(contents()->ShouldDisplayURL());
  EXPECT_TRUE(contents_wrapper()->favicon_tab_helper()->ShouldDisplayFavicon());
  EXPECT_FALSE(
      contents_wrapper()->bookmark_tab_helper()->ShouldShowBookmarkBar());
  EXPECT_FALSE(contents()->FocusLocationBarByDefault());

  // Commit the load, the state should be the same.
  rvh()->SendNavigate(1, std_url);
  EXPECT_TRUE(contents()->ShouldDisplayURL());
  EXPECT_TRUE(contents_wrapper()->favicon_tab_helper()->ShouldDisplayFavicon());
  EXPECT_FALSE(
      contents_wrapper()->bookmark_tab_helper()->ShouldShowBookmarkBar());
  EXPECT_FALSE(contents()->FocusLocationBarByDefault());

  // Start a pending load for a WebUI.
  GURL new_tab_url(chrome::kChromeUINewTabURL);
  controller().LoadURL(new_tab_url, GURL(), PageTransition::LINK);
  EXPECT_FALSE(contents()->ShouldDisplayURL());
  EXPECT_TRUE(contents_wrapper()->favicon_tab_helper()->ShouldDisplayFavicon());
  EXPECT_FALSE(
      contents_wrapper()->bookmark_tab_helper()->ShouldShowBookmarkBar());
  EXPECT_TRUE(contents()->FocusLocationBarByDefault());

  // Committing Web UI is tested above.
}

class TabContentsForFocusTest : public TestTabContents {
 public:
  TabContentsForFocusTest(content::BrowserContext* browser_context,
                          SiteInstance* instance)
      : TestTabContents(browser_context, instance), focus_called_(0) {
  }

  virtual void SetFocusToLocationBar(bool select_all) { ++focus_called_; }
  int focus_called() const { return focus_called_; }

 private:
  int focus_called_;
};

TEST_F(WebUITest, FocusOnNavigate) {
  // Setup.  |tc| will be used to track when we try to focus the location bar.
  TabContentsForFocusTest* tc = new TabContentsForFocusTest(
      contents()->browser_context(),
      SiteInstance::CreateSiteInstance(contents()->browser_context()));
  tc->controller().CopyStateFrom(controller());
  SetContents(tc);
  int page_id = 200;

  // Load the NTP.
  GURL new_tab_url(chrome::kChromeUINewTabURL);
  controller().LoadURL(new_tab_url, GURL(), PageTransition::LINK);
  rvh()->SendNavigate(page_id, new_tab_url);

  // Navigate to another page.
  GURL next_url("http://google.com/");
  int next_page_id = page_id + 1;
  controller().LoadURL(next_url, GURL(), PageTransition::LINK);
  TestRenderViewHost* old_rvh = rvh();
  old_rvh->SendShouldCloseACK(true);
  pending_rvh()->SendNavigate(next_page_id, next_url);
  old_rvh->OnSwapOutACK();

  // Navigate back.  Should focus the location bar.
  int focus_called = tc->focus_called();
  ASSERT_TRUE(controller().CanGoBack());
  controller().GoBack();
  old_rvh = rvh();
  old_rvh->SendShouldCloseACK(true);
  pending_rvh()->SendNavigate(page_id, new_tab_url);
  old_rvh->OnSwapOutACK();
  EXPECT_LT(focus_called, tc->focus_called());

  // Navigate forward.  Shouldn't focus the location bar.
  focus_called = tc->focus_called();
  ASSERT_TRUE(controller().CanGoForward());
  controller().GoForward();
  old_rvh = rvh();
  old_rvh->SendShouldCloseACK(true);
  pending_rvh()->SendNavigate(next_page_id, next_url);
  old_rvh->OnSwapOutACK();
  EXPECT_EQ(focus_called, tc->focus_called());
}
<commit_msg>ntp4: fix tests due to new default ntp<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 "chrome/browser/favicon/favicon_tab_helper.h"
#include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h"
#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
#include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h"
#include "chrome/common/url_constants.h"
#include "chrome/test/base/testing_profile.h"
#include "content/browser/browser_thread.h"
#include "content/browser/site_instance.h"
#include "content/browser/tab_contents/navigation_controller.h"
#include "content/browser/tab_contents/test_tab_contents.h"
#include "testing/gtest/include/gtest/gtest.h"

class WebUITest : public TabContentsWrapperTestHarness {
 public:
  WebUITest() : ui_thread_(BrowserThread::UI, MessageLoop::current()) {}

  // Tests navigating with a Web UI from a fresh (nothing pending or committed)
  // state, through pending, committed, then another navigation. The first page
  // ID that we should use is passed as a parameter. We'll use the next two
  // values. This must be increasing for the life of the tests.
  static void DoNavigationTest(TabContentsWrapper* wrapper, int page_id) {
    TabContents* contents = wrapper->tab_contents();
    NavigationController* controller = &contents->controller();

    // Start a pending load.
    GURL new_tab_url(chrome::kChromeUINewTabURL);
    controller->LoadURL(new_tab_url, GURL(), PageTransition::LINK);

    // The navigation entry should be pending with no committed entry.
    ASSERT_TRUE(controller->pending_entry());
    ASSERT_FALSE(controller->GetLastCommittedEntry());

    // Check the things the pending Web UI should have set.
    EXPECT_FALSE(contents->ShouldDisplayURL());
    EXPECT_FALSE(wrapper->favicon_tab_helper()->ShouldDisplayFavicon());
    EXPECT_TRUE(contents->FocusLocationBarByDefault());

    // Now commit the load.
    static_cast<TestRenderViewHost*>(
        contents->render_view_host())->SendNavigate(page_id, new_tab_url);

    // The same flags should be set as before now that the load has committed.
    EXPECT_FALSE(contents->ShouldDisplayURL());
    EXPECT_FALSE(wrapper->favicon_tab_helper()->ShouldDisplayFavicon());
    EXPECT_TRUE(contents->FocusLocationBarByDefault());

    // Start a pending navigation to a regular page.
    GURL next_url("http://google.com/");
    controller->LoadURL(next_url, GURL(), PageTransition::LINK);

    // Check the flags. Some should reflect the new page (URL, title), some
    // should reflect the old one (bookmark bar) until it has committed.
    EXPECT_TRUE(contents->ShouldDisplayURL());
    EXPECT_TRUE(wrapper->favicon_tab_helper()->ShouldDisplayFavicon());
    EXPECT_FALSE(contents->FocusLocationBarByDefault());

    // Commit the regular page load. Note that we must send it to the "pending"
    // RenderViewHost if there is one, since this transition will also cause a
    // process transition, and our RVH pointer will be the "committed" one.
    // In the second call to this function from WebUIToStandard, it won't
    // actually be pending, which is the point of this test.
    if (contents->render_manager()->pending_render_view_host()) {
      static_cast<TestRenderViewHost*>(
          contents->render_manager()->pending_render_view_host())->SendNavigate(
              page_id + 1, next_url);
    } else {
      static_cast<TestRenderViewHost*>(
          contents->render_view_host())->SendNavigate(page_id + 1, next_url);
    }

    // The state should now reflect a regular page.
    EXPECT_TRUE(contents->ShouldDisplayURL());
    EXPECT_TRUE(wrapper->favicon_tab_helper()->ShouldDisplayFavicon());
    EXPECT_FALSE(contents->FocusLocationBarByDefault());
  }

 private:
  BrowserThread ui_thread_;

  DISALLOW_COPY_AND_ASSIGN(WebUITest);
};

// Tests that the New Tab Page flags are correctly set and propogated by
// TabContents when we first navigate to a Web UI page, then to a standard
// non-DOM-UI page.
TEST_F(WebUITest, WebUIToStandard) {
  DoNavigationTest(contents_wrapper(), 1);

  // Test the case where we're not doing the initial navigation. This is
  // slightly different than the very-first-navigation case since the
  // SiteInstance will be the same (the original TabContents must still be
  // alive), which will trigger different behavior in RenderViewHostManager.
  TestTabContents* contents2 = new TestTabContents(profile_.get(), NULL);
  TabContentsWrapper wrapper2(contents2);

  DoNavigationTest(&wrapper2, 101);
}

TEST_F(WebUITest, WebUIToWebUI) {
  // Do a load (this state is tested above).
  GURL new_tab_url(chrome::kChromeUINewTabURL);
  controller().LoadURL(new_tab_url, GURL(), PageTransition::LINK);
  rvh()->SendNavigate(1, new_tab_url);

  // Start another pending load of the new tab page.
  controller().LoadURL(new_tab_url, GURL(), PageTransition::LINK);
  rvh()->SendNavigate(2, new_tab_url);

  // The flags should be the same as the non-pending state.
  EXPECT_FALSE(contents()->ShouldDisplayURL());
  EXPECT_FALSE(
      contents_wrapper()->favicon_tab_helper()->ShouldDisplayFavicon());
  EXPECT_TRUE(contents()->FocusLocationBarByDefault());
}

TEST_F(WebUITest, StandardToWebUI) {
  // Start a pending navigation to a regular page.
  GURL std_url("http://google.com/");

  controller().LoadURL(std_url, GURL(), PageTransition::LINK);

  // The state should now reflect the default.
  EXPECT_TRUE(contents()->ShouldDisplayURL());
  EXPECT_TRUE(contents_wrapper()->favicon_tab_helper()->ShouldDisplayFavicon());
  EXPECT_FALSE(contents()->FocusLocationBarByDefault());

  // Commit the load, the state should be the same.
  rvh()->SendNavigate(1, std_url);
  EXPECT_TRUE(contents()->ShouldDisplayURL());
  EXPECT_TRUE(contents_wrapper()->favicon_tab_helper()->ShouldDisplayFavicon());
  EXPECT_FALSE(contents()->FocusLocationBarByDefault());

  // Start a pending load for a WebUI.
  GURL new_tab_url(chrome::kChromeUINewTabURL);
  controller().LoadURL(new_tab_url, GURL(), PageTransition::LINK);
  EXPECT_FALSE(contents()->ShouldDisplayURL());
  EXPECT_TRUE(contents_wrapper()->favicon_tab_helper()->ShouldDisplayFavicon());
  EXPECT_TRUE(contents()->FocusLocationBarByDefault());

  // Committing Web UI is tested above.
}

class TabContentsForFocusTest : public TestTabContents {
 public:
  TabContentsForFocusTest(content::BrowserContext* browser_context,
                          SiteInstance* instance)
      : TestTabContents(browser_context, instance), focus_called_(0) {
  }

  virtual void SetFocusToLocationBar(bool select_all) { ++focus_called_; }
  int focus_called() const { return focus_called_; }

 private:
  int focus_called_;
};

TEST_F(WebUITest, FocusOnNavigate) {
  // Setup.  |tc| will be used to track when we try to focus the location bar.
  TabContentsForFocusTest* tc = new TabContentsForFocusTest(
      contents()->browser_context(),
      SiteInstance::CreateSiteInstance(contents()->browser_context()));
  tc->controller().CopyStateFrom(controller());
  SetContents(tc);
  int page_id = 200;

  // Load the NTP.
  GURL new_tab_url(chrome::kChromeUINewTabURL);
  controller().LoadURL(new_tab_url, GURL(), PageTransition::LINK);
  rvh()->SendNavigate(page_id, new_tab_url);

  // Navigate to another page.
  GURL next_url("http://google.com/");
  int next_page_id = page_id + 1;
  controller().LoadURL(next_url, GURL(), PageTransition::LINK);
  TestRenderViewHost* old_rvh = rvh();
  old_rvh->SendShouldCloseACK(true);
  pending_rvh()->SendNavigate(next_page_id, next_url);
  old_rvh->OnSwapOutACK();

  // Navigate back.  Should focus the location bar.
  int focus_called = tc->focus_called();
  ASSERT_TRUE(controller().CanGoBack());
  controller().GoBack();
  old_rvh = rvh();
  old_rvh->SendShouldCloseACK(true);
  pending_rvh()->SendNavigate(page_id, new_tab_url);
  old_rvh->OnSwapOutACK();
  EXPECT_LT(focus_called, tc->focus_called());

  // Navigate forward.  Shouldn't focus the location bar.
  focus_called = tc->focus_called();
  ASSERT_TRUE(controller().CanGoForward());
  controller().GoForward();
  old_rvh = rvh();
  old_rvh->SendShouldCloseACK(true);
  pending_rvh()->SendNavigate(next_page_id, next_url);
  old_rvh->OnSwapOutACK();
  EXPECT_EQ(focus_called, tc->focus_called());
}
<|endoftext|>


<commit_before>// Copyright (c) 2006-2008 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 <windows.h>

#include "chrome/installer/util/logging_installer.h"

#include "base/command_line.h"
#include "base/file_path.h"
#include "base/logging.h"
#include "base/path_service.h"
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
#include "chrome/installer/util/master_preferences.h"
#include "chrome/installer/util/master_preferences_constants.h"
#include "chrome/installer/util/util_constants.h"

namespace installer {

// This should be true for the period between the end of
// InitInstallerLogging() and the beginning of EndInstallerLogging().
bool installer_logging_ = false;

void InitInstallerLogging(const installer_util::MasterPreferences& prefs) {
  if (installer_logging_)
    return;

  bool value = false;
  if (prefs.GetBool(installer_util::master_preferences::kDisableLogging,
                    &value) && value) {
    installer_logging_ = true;
    return;
  }

  logging::InitLogging(GetLogFilePath(prefs).value().c_str(),
                       logging::LOG_ONLY_TO_FILE,
                       logging::LOCK_LOG_FILE,
                       logging::DELETE_OLD_LOG_FILE);

  if (prefs.GetBool(installer_util::master_preferences::kVerboseLogging,
                    &value) && value) {
    logging::SetMinLogLevel(logging::LOG_VERBOSE);
  } else {
    logging::SetMinLogLevel(logging::LOG_ERROR);
  }

  installer_logging_ = true;
}

void EndInstallerLogging() {
  logging::CloseLogFile();

  installer_logging_ = false;
}

FilePath GetLogFilePath(const installer_util::MasterPreferences& prefs) {
  std::string path;
  prefs.GetString(installer_util::master_preferences::kLogFile, &path);
  if (!path.empty()) {
    return FilePath(UTF8ToWide(path));
  }

  std::wstring log_filename = prefs.install_chrome_frame() ?
      L"chrome_frame_installer.log" : L"chrome_installer.log";

  FilePath log_path;
  if (PathService::Get(base::DIR_TEMP, &log_path)) {
    log_path = log_path.Append(log_filename);
    return log_path;
  } else {
    return FilePath(log_filename);
  }
}

}  // namespace installer
<commit_msg>Land http://codereview.chromium.org/5049001/ again (sigh)<commit_after>// Copyright (c) 2006-2008 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 <windows.h>

#include "chrome/installer/util/logging_installer.h"

#include "base/command_line.h"
#include "base/file_path.h"
#include "base/logging.h"
#include "base/logging_win.h"
#include "base/path_service.h"
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
#include "chrome/installer/util/master_preferences.h"
#include "chrome/installer/util/master_preferences_constants.h"
#include "chrome/installer/util/util_constants.h"

// {93BCE0BF-3FAF-43b1-9E28-BEB6FAB5ECE7}
static const GUID kSetupTraceProvider = { 0x93bce0bf, 0x3faf, 0x43b1,
    { 0x9e, 0x28, 0xbe, 0xb6, 0xfa, 0xb5, 0xec, 0xe7 } };

namespace installer {

// This should be true for the period between the end of
// InitInstallerLogging() and the beginning of EndInstallerLogging().
bool installer_logging_ = false;

void InitInstallerLogging(const installer_util::MasterPreferences& prefs) {
  if (installer_logging_)
    return;

  bool value = false;
  if (prefs.GetBool(installer_util::master_preferences::kDisableLogging,
                    &value) && value) {
    installer_logging_ = true;
    return;
  }

  logging::InitLogging(GetLogFilePath(prefs).value().c_str(),
                       logging::LOG_ONLY_TO_FILE,
                       logging::LOCK_LOG_FILE,
                       logging::DELETE_OLD_LOG_FILE);

  if (prefs.GetBool(installer_util::master_preferences::kVerboseLogging,
                    &value) && value) {
    logging::SetMinLogLevel(logging::LOG_VERBOSE);
  } else {
    logging::SetMinLogLevel(logging::LOG_ERROR);
  }

  // Enable ETW logging.
  logging::LogEventProvider::Initialize(kSetupTraceProvider);

  installer_logging_ = true;
}

void EndInstallerLogging() {
  logging::CloseLogFile();

  installer_logging_ = false;
}

FilePath GetLogFilePath(const installer_util::MasterPreferences& prefs) {
  std::string path;
  prefs.GetString(installer_util::master_preferences::kLogFile, &path);
  if (!path.empty()) {
    return FilePath(UTF8ToWide(path));
  }

  std::wstring log_filename = prefs.install_chrome_frame() ?
      L"chrome_frame_installer.log" : L"chrome_installer.log";

  FilePath log_path;
  if (PathService::Get(base::DIR_TEMP, &log_path)) {
    log_path = log_path.Append(log_filename);
    return log_path;
  } else {
    return FilePath(log_filename);
  }
}

}  // namespace installer
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: b3drange.cxx,v $
 *
 *  $Revision: 1.7 $
 *
 *  last change: $Author: kz $ $Date: 2005-11-02 14:00:22 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

#ifndef _BGFX_RANGE_B3DRANGE_HXX
#include <basegfx/range/b3drange.hxx>
#endif

#ifndef _BGFX_RANGE_B3IRANGE_HXX
#include <basegfx/range/b3irange.hxx>
#endif

#ifndef _BGFX_NUMERIC_FTOOLS_HXX
#include <basegfx/numeric/ftools.hxx>
#endif

namespace basegfx
{
    B3DRange::B3DRange(const B3IRange& rRange) :
        maRangeX(),
        maRangeY(),
        maRangeZ()
    {
        if( !rRange.isEmpty() )
        {
            maRangeX = rRange.getMinX();
            maRangeY = rRange.getMinY();
            maRangeZ = rRange.getMinZ();

            maRangeX.expand( rRange.getMaxX() );
            maRangeY.expand( rRange.getMaxY() );
            maRangeZ.expand( rRange.getMaxZ() );
        }
    }

    B3IRange fround(const B3DRange& rRange )
    {
        return rRange.isEmpty() ?
            B3IRange() :
            B3IRange(fround(rRange.getMinX()),
                     fround(rRange.getMinY()),
                     fround(rRange.getMinZ()),
                     fround(rRange.getMaxX()),
                     fround(rRange.getMaxY()),
                     fround(rRange.getMaxZ()));
    }

} // end of namespace basegfx

// eof
<commit_msg>INTEGRATION: CWS pchfix02 (1.7.30); FILE MERGED 2006/09/01 17:16:39 kaib 1.7.30.1: #i68856# Added header markers and pch files<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: b3drange.cxx,v $
 *
 *  $Revision: 1.8 $
 *
 *  last change: $Author: obo $ $Date: 2006-09-17 08:05:24 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_basegfx.hxx"

#ifndef _BGFX_RANGE_B3DRANGE_HXX
#include <basegfx/range/b3drange.hxx>
#endif

#ifndef _BGFX_RANGE_B3IRANGE_HXX
#include <basegfx/range/b3irange.hxx>
#endif

#ifndef _BGFX_NUMERIC_FTOOLS_HXX
#include <basegfx/numeric/ftools.hxx>
#endif

namespace basegfx
{
    B3DRange::B3DRange(const B3IRange& rRange) :
        maRangeX(),
        maRangeY(),
        maRangeZ()
    {
        if( !rRange.isEmpty() )
        {
            maRangeX = rRange.getMinX();
            maRangeY = rRange.getMinY();
            maRangeZ = rRange.getMinZ();

            maRangeX.expand( rRange.getMaxX() );
            maRangeY.expand( rRange.getMaxY() );
            maRangeZ.expand( rRange.getMaxZ() );
        }
    }

    B3IRange fround(const B3DRange& rRange )
    {
        return rRange.isEmpty() ?
            B3IRange() :
            B3IRange(fround(rRange.getMinX()),
                     fround(rRange.getMinY()),
                     fround(rRange.getMinZ()),
                     fround(rRange.getMaxX()),
                     fround(rRange.getMaxY()),
                     fround(rRange.getMaxZ()));
    }

} // end of namespace basegfx

// eof
<|endoftext|>


<commit_before>/*
 * Author: Brendan Le Foll <brendan.le.foll@intel.com>
 * Copyright © 2014 Intel Corporation
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to
 * deal in the Software without restriction, including without limitation the
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 * sell copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 * IN THE SOFTWARE.
 */

#pragma once

/** @file
 *
 * This file defines the basic shared types for libmraa
 * this file is different to common.h in that swig takes this as an input
 */

namespace mraa
{

//These enums must match the enums in types.h

/**
 * MRAA supported platform types
 */
typedef enum {
    INTEL_GALILEO_GEN1 = 0,    /**< The Generation 1 Galileo platform (RevD) */
    INTEL_GALILEO_GEN2 = 1,    /**< The Generation 2 Galileo platform (RevG/H) */
    INTEL_EDISON_FAB_C = 2,    /**< The Intel Edison (FAB C) */
    INTEL_DE3815 = 3,          /**< The Intel DE3815 Baytrail NUC */
    INTEL_MINNOWBOARD_MAX = 4, /**< The Intel Minnow Board Max */
    RASPBERRY_PI = 5,          /**< The different Raspberry PI Models -like  A,B,A+,B+ */
    BEAGLEBONE = 6,            /**< The different BeagleBone Black Modes B/C */
    BANANA = 7,                /**< Allwinner A20 based Banana Pi and Banana Pro */

    UNKNOWN_PLATFORM =
    99 /**< An unknown platform type, typically will load INTEL_GALILEO_GEN1 */
} Platform;

/**
 * Intel edison miniboard numbering enum
 */
typedef enum {
    INTEL_EDISON_MINIBOARD_J17_1 = 0,
    INTEL_EDISON_MINIBOARD_J17_5 = 4,
    INTEL_EDISON_MINIBOARD_J17_7 = 6,
    INTEL_EDISON_MINIBOARD_J17_8 = 7,
    INTEL_EDISON_MINIBOARD_J17_9 = 8,
    INTEL_EDISON_MINIBOARD_J17_10 = 9,
    INTEL_EDISON_MINIBOARD_J17_11 = 10,
    INTEL_EDISON_MINIBOARD_J17_12 = 11,
    INTEL_EDISON_MINIBOARD_J17_14 = 13,
    INTEL_EDISON_MINIBOARD_J18_1 = 14,
    INTEL_EDISON_MINIBOARD_J18_2 = 15,
    INTEL_EDISON_MINIBOARD_J18_6 = 19,
    INTEL_EDISON_MINIBOARD_J18_7 = 20,
    INTEL_EDISON_MINIBOARD_J18_8 = 21,
    INTEL_EDISON_MINIBOARD_J18_10 = 23,
    INTEL_EDISON_MINIBOARD_J18_11 = 24,
    INTEL_EDISON_MINIBOARD_J18_12 = 25,
    INTEL_EDISON_MINIBOARD_J18_13 = 26,
    INTEL_EDISON_MINIBOARD_J19_4 = 31,
    INTEL_EDISON_MINIBOARD_J19_5 = 32,
    INTEL_EDISON_MINIBOARD_J19_6 = 33,
    INTEL_EDISON_MINIBOARD_J19_8 = 35,
    INTEL_EDISON_MINIBOARD_J19_9 = 36,
    INTEL_EDISON_MINIBOARD_J19_10 = 37,
    INTEL_EDISON_MINIBOARD_J19_11 = 38,
    INTEL_EDISON_MINIBOARD_J19_12 = 39,
    INTEL_EDISON_MINIBOARD_J19_13 = 40,
    INTEL_EDISON_MINIBOARD_J19_14 = 41,
    INTEL_EDISON_MINIBOARD_J20_3 = 44,
    INTEL_EDISON_MINIBOARD_J20_4 = 45,
    INTEL_EDISON_MINIBOARD_J20_5 = 46,
    INTEL_EDISON_MINIBOARD_J20_6 = 47,
    INTEL_EDISON_MINIBOARD_J20_7 = 48,
    INTEL_EDISON_MINIBOARD_J20_8 = 49,
    INTEL_EDISON_MINIBOARD_J20_9 = 50,
    INTEL_EDISON_MINIBOARD_J20_10 = 51,
    INTEL_EDISON_MINIBOARD_J20_11 = 52,
    INTEL_EDISON_MINIBOARD_J20_12 = 53,
    INTEL_EDISON_MINIBOARD_J20_13 = 54,
    INTEL_EDISON_MINIBOARD_J20_14 = 55
} IntelEdisonMiniboard;

/**
 * Intel Edison raw GPIO numbering enum
 */
typedef enum {
    INTEL_EDISON_GP182 = 0,
    INTEL_EDISON_GP135 = 4,
    INTEL_EDISON_GP27 = 6,
    INTEL_EDISON_GP20 = 7,
    INTEL_EDISON_GP28 = 8,
    INTEL_EDISON_GP111 = 0,
    INTEL_EDISON_GP109 = 10,
    INTEL_EDISON_GP115 = 11,
    INTEL_EDISON_GP128 = 13,
    INTEL_EDISON_GP13 = 14,
    INTEL_EDISON_GP165 = 15,
    INTEL_EDISON_GP19 = 19,
    INTEL_EDISON_GP12 = 20,
    INTEL_EDISON_GP183 = 21,
    INTEL_EDISON_GP110 = 23,
    INTEL_EDISON_GP114 = 24,
    INTEL_EDISON_GP129 = 25,
    INTEL_EDISON_GP130 = 26,
    INTEL_EDISON_GP44 = 31,
    INTEL_EDISON_GP46 = 32,
    INTEL_EDISON_GP48 = 33,
    INTEL_EDISON_GP131 = 35,
    INTEL_EDISON_GP14 = 36,
    INTEL_EDISON_GP40 = 37,
    INTEL_EDISON_GP43 = 38,
    INTEL_EDISON_GP77 = 39,
    INTEL_EDISON_GP82 = 40,
    INTEL_EDISON_GP83 = 41,
    INTEL_EDISON_GP134 = 44,
    INTEL_EDISON_GP45 = 45,
    INTEL_EDISON_GP47 = 46,
    INTEL_EDISON_GP49 = 47,
    INTEL_EDISON_GP15 = 48,
    INTEL_EDISON_GP84 = 49,
    INTEL_EDISON_GP42 = 50,
    INTEL_EDISON_GP41 = 51,
    INTEL_EDISON_GP78 = 52,
    INTEL_EDISON_GP79 = 53,
    INTEL_EDISON_GP80 = 54,
    INTEL_EDISON_GP81 = 55
} IntelEdison;

/**
* Raspberry PI Wiring compatible numbering enum
*/
typedef enum {
    RASPBERRY_WIRING_PIN8 = 3,
    RASPBERRY_WIRING_PIN9 = 5,
    RASPBERRY_WIRING_PIN7 = 7,
    RASPBERRY_WIRING_PIN15 = 8,
    RASPBERRY_WIRING_PIN16 = 10,
    RASPBERRY_WIRING_PIN0 = 11,
    RASPBERRY_WIRING_PIN1 = 12,
    RASPBERRY_WIRING_PIN2 = 13,
    RASPBERRY_WIRING_PIN3 = 15,
    RASPBERRY_WIRING_PIN4 = 16,
    RASPBERRY_WIRING_PIN5 = 18,
    RASPBERRY_WIRING_PIN12 = 19,
    RASPBERRY_WIRING_PIN13 = 21,
    RASPBERRY_WIRING_PIN6 = 22,
    RASPBERRY_WIRING_PIN14 = 23,
    RASPBERRY_WIRING_PIN10 = 24,
    RASPBERRY_WIRING_PIN11 = 26,
    RASPBERRY_WIRING_PIN17 = 29, // RPi B V2
    RASPBERRY_WIRING_PIN21 = 29,
    RASPBERRY_WIRING_PIN18 = 30, // RPi B V2
    RASPBERRY_WIRING_PIN19 = 31, // RPI B V2
    RASPBERRY_WIRING_PIN22 = 31,
    RASPBERRY_WIRING_PIN20 = 32, // RPi B V2
    RASPBERRY_WIRING_PIN26 = 32,
    RASPBERRY_WIRING_PIN23 = 33,
    RASPBERRY_WIRING_PIN24 = 35,
    RASPBERRY_WIRING_PIN27 = 36,
    RASPBERRY_WIRING_PIN25 = 37,
    RASPBERRY_WIRING_PIN28 = 38,
    RASPBERRY_WIRING_PIN29 = 40
} RaspberryWiring;

/**
 * MRAA return codes
 */
typedef enum {
    SUCCESS = 0,                             /**< Expected response */
    ERROR_FEATURE_NOT_IMPLEMENTED = 1,       /**< Feature TODO */
    ERROR_FEATURE_NOT_SUPPORTED = 2,         /**< Feature not supported by HW */
    ERROR_INVALID_VERBOSITY_LEVEL = 3,       /**< Verbosity level wrong */
    ERROR_INVALID_PARAMETER = 4,             /**< Parameter invalid */
    ERROR_INVALID_HANDLE = 5,                /**< Handle invalid */
    ERROR_NO_RESOURCES = 6,                  /**< No resource of that type avail */
    ERROR_INVALID_RESOURCE = 7,              /**< Resource invalid */
    ERROR_INVALID_QUEUE_TYPE = 8,            /**< Queue type incorrect */
    ERROR_NO_DATA_AVAILABLE = 9,             /**< No data available */
    ERROR_INVALID_PLATFORM = 10,             /**< Platform not recognised */
    ERROR_PLATFORM_NOT_INITIALISED = 11,     /**< Board information not initialised */
    ERROR_PLATFORM_ALREADY_INITIALISED = 0,  /**< Board is already initialised, same as SUCCESS */

    ERROR_UNSPECIFIED = 99 /**< Unknown Error */
} Result;

/**
 * Enum representing different possible modes for a pin.
 */
typedef enum {
    PIN_VALID = 0,     /**< Pin Valid */
    PIN_GPIO = 1,      /**< General Purpose IO */
    PIN_PWM = 2,       /**< Pulse Width Modulation */
    PIN_FAST_GPIO = 3, /**< Faster GPIO */
    PIN_SPI = 4,       /**< SPI */
    PIN_I2C = 5,       /**< I2C */
    PIN_AIO = 6,       /**< Analog in */
    PIN_UART = 7       /**< UART */
} Pinmodes;

/**
 * Enum reprensenting different i2c speeds/modes
 */
typedef enum {
    I2C_STD = 0,  /**< up to 100Khz */
    I2C_FAST = 1, /**< up to 400Khz */
    I2C_HIGH = 2  /**< up to 3.4Mhz */
} I2cMode;

typedef enum {
    UART_PARITY_NONE = 0,
    UART_PARITY_EVEN = 1,
    UART_PARITY_ODD = 2,
    UART_PARITY_MARK = 3,
    UART_PARITY_SPACE = 4
} UartParity;

}
<commit_msg>types.hpp: Add C++ platform types<commit_after>/*
 * Author: Brendan Le Foll <brendan.le.foll@intel.com>
 * Copyright © 2014 Intel Corporation
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to
 * deal in the Software without restriction, including without limitation the
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 * sell copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 * IN THE SOFTWARE.
 */

#pragma once

/** @file
 *
 * This file defines the basic shared types for libmraa
 * this file is different to common.h in that swig takes this as an input
 */

namespace mraa
{

//These enums must match the enums in types.h

/**
 * MRAA supported platform types
 */
typedef enum {
    INTEL_GALILEO_GEN1 = 0,    /**< The Generation 1 Galileo platform (RevD) */
    INTEL_GALILEO_GEN2 = 1,    /**< The Generation 2 Galileo platform (RevG/H) */
    INTEL_EDISON_FAB_C = 2,    /**< The Intel Edison (FAB C) */
    INTEL_DE3815 = 3,          /**< The Intel DE3815 Baytrail NUC */
    INTEL_MINNOWBOARD_MAX = 4, /**< The Intel Minnow Board Max */
    RASPBERRY_PI = 5,          /**< The different Raspberry PI Models -like  A,B,A+,B+ */
    BEAGLEBONE = 6,            /**< The different BeagleBone Black Modes B/C */
    BANANA = 7,                /**< Allwinner A20 based Banana Pi and Banana Pro */
    INTEL_NUC5 = 8,            /**< The Intel 5th generations Broadwell NUCs */
    96BOARDS = 9,              /**< Linaro 96boards */
    INTEL_SOFIA_3GR = 10,      /**< The Intel SoFIA 3GR */
    INTEL_CHERRYHILLS = 11,    /**< The Intel Braswell Cherryhills */

    FTDI_FT4222 = 256,         /**< FTDI FT4222 USB to i2c bridge */

    FIRMATA = 1024,            /**< Firmata uart platform/bridge */

    NULL_PLATFORM = 98,
    UNKNOWN_PLATFORM =
    99 /**< An unknown platform type, typically will load INTEL_GALILEO_GEN1 */
} Platform;

/**
 * Intel edison miniboard numbering enum
 */
typedef enum {
    INTEL_EDISON_MINIBOARD_J17_1 = 0,
    INTEL_EDISON_MINIBOARD_J17_5 = 4,
    INTEL_EDISON_MINIBOARD_J17_7 = 6,
    INTEL_EDISON_MINIBOARD_J17_8 = 7,
    INTEL_EDISON_MINIBOARD_J17_9 = 8,
    INTEL_EDISON_MINIBOARD_J17_10 = 9,
    INTEL_EDISON_MINIBOARD_J17_11 = 10,
    INTEL_EDISON_MINIBOARD_J17_12 = 11,
    INTEL_EDISON_MINIBOARD_J17_14 = 13,
    INTEL_EDISON_MINIBOARD_J18_1 = 14,
    INTEL_EDISON_MINIBOARD_J18_2 = 15,
    INTEL_EDISON_MINIBOARD_J18_6 = 19,
    INTEL_EDISON_MINIBOARD_J18_7 = 20,
    INTEL_EDISON_MINIBOARD_J18_8 = 21,
    INTEL_EDISON_MINIBOARD_J18_10 = 23,
    INTEL_EDISON_MINIBOARD_J18_11 = 24,
    INTEL_EDISON_MINIBOARD_J18_12 = 25,
    INTEL_EDISON_MINIBOARD_J18_13 = 26,
    INTEL_EDISON_MINIBOARD_J19_4 = 31,
    INTEL_EDISON_MINIBOARD_J19_5 = 32,
    INTEL_EDISON_MINIBOARD_J19_6 = 33,
    INTEL_EDISON_MINIBOARD_J19_8 = 35,
    INTEL_EDISON_MINIBOARD_J19_9 = 36,
    INTEL_EDISON_MINIBOARD_J19_10 = 37,
    INTEL_EDISON_MINIBOARD_J19_11 = 38,
    INTEL_EDISON_MINIBOARD_J19_12 = 39,
    INTEL_EDISON_MINIBOARD_J19_13 = 40,
    INTEL_EDISON_MINIBOARD_J19_14 = 41,
    INTEL_EDISON_MINIBOARD_J20_3 = 44,
    INTEL_EDISON_MINIBOARD_J20_4 = 45,
    INTEL_EDISON_MINIBOARD_J20_5 = 46,
    INTEL_EDISON_MINIBOARD_J20_6 = 47,
    INTEL_EDISON_MINIBOARD_J20_7 = 48,
    INTEL_EDISON_MINIBOARD_J20_8 = 49,
    INTEL_EDISON_MINIBOARD_J20_9 = 50,
    INTEL_EDISON_MINIBOARD_J20_10 = 51,
    INTEL_EDISON_MINIBOARD_J20_11 = 52,
    INTEL_EDISON_MINIBOARD_J20_12 = 53,
    INTEL_EDISON_MINIBOARD_J20_13 = 54,
    INTEL_EDISON_MINIBOARD_J20_14 = 55
} IntelEdisonMiniboard;

/**
 * Intel Edison raw GPIO numbering enum
 */
typedef enum {
    INTEL_EDISON_GP182 = 0,
    INTEL_EDISON_GP135 = 4,
    INTEL_EDISON_GP27 = 6,
    INTEL_EDISON_GP20 = 7,
    INTEL_EDISON_GP28 = 8,
    INTEL_EDISON_GP111 = 0,
    INTEL_EDISON_GP109 = 10,
    INTEL_EDISON_GP115 = 11,
    INTEL_EDISON_GP128 = 13,
    INTEL_EDISON_GP13 = 14,
    INTEL_EDISON_GP165 = 15,
    INTEL_EDISON_GP19 = 19,
    INTEL_EDISON_GP12 = 20,
    INTEL_EDISON_GP183 = 21,
    INTEL_EDISON_GP110 = 23,
    INTEL_EDISON_GP114 = 24,
    INTEL_EDISON_GP129 = 25,
    INTEL_EDISON_GP130 = 26,
    INTEL_EDISON_GP44 = 31,
    INTEL_EDISON_GP46 = 32,
    INTEL_EDISON_GP48 = 33,
    INTEL_EDISON_GP131 = 35,
    INTEL_EDISON_GP14 = 36,
    INTEL_EDISON_GP40 = 37,
    INTEL_EDISON_GP43 = 38,
    INTEL_EDISON_GP77 = 39,
    INTEL_EDISON_GP82 = 40,
    INTEL_EDISON_GP83 = 41,
    INTEL_EDISON_GP134 = 44,
    INTEL_EDISON_GP45 = 45,
    INTEL_EDISON_GP47 = 46,
    INTEL_EDISON_GP49 = 47,
    INTEL_EDISON_GP15 = 48,
    INTEL_EDISON_GP84 = 49,
    INTEL_EDISON_GP42 = 50,
    INTEL_EDISON_GP41 = 51,
    INTEL_EDISON_GP78 = 52,
    INTEL_EDISON_GP79 = 53,
    INTEL_EDISON_GP80 = 54,
    INTEL_EDISON_GP81 = 55
} IntelEdison;

/**
* Raspberry PI Wiring compatible numbering enum
*/
typedef enum {
    RASPBERRY_WIRING_PIN8 = 3,
    RASPBERRY_WIRING_PIN9 = 5,
    RASPBERRY_WIRING_PIN7 = 7,
    RASPBERRY_WIRING_PIN15 = 8,
    RASPBERRY_WIRING_PIN16 = 10,
    RASPBERRY_WIRING_PIN0 = 11,
    RASPBERRY_WIRING_PIN1 = 12,
    RASPBERRY_WIRING_PIN2 = 13,
    RASPBERRY_WIRING_PIN3 = 15,
    RASPBERRY_WIRING_PIN4 = 16,
    RASPBERRY_WIRING_PIN5 = 18,
    RASPBERRY_WIRING_PIN12 = 19,
    RASPBERRY_WIRING_PIN13 = 21,
    RASPBERRY_WIRING_PIN6 = 22,
    RASPBERRY_WIRING_PIN14 = 23,
    RASPBERRY_WIRING_PIN10 = 24,
    RASPBERRY_WIRING_PIN11 = 26,
    RASPBERRY_WIRING_PIN17 = 29, // RPi B V2
    RASPBERRY_WIRING_PIN21 = 29,
    RASPBERRY_WIRING_PIN18 = 30, // RPi B V2
    RASPBERRY_WIRING_PIN19 = 31, // RPI B V2
    RASPBERRY_WIRING_PIN22 = 31,
    RASPBERRY_WIRING_PIN20 = 32, // RPi B V2
    RASPBERRY_WIRING_PIN26 = 32,
    RASPBERRY_WIRING_PIN23 = 33,
    RASPBERRY_WIRING_PIN24 = 35,
    RASPBERRY_WIRING_PIN27 = 36,
    RASPBERRY_WIRING_PIN25 = 37,
    RASPBERRY_WIRING_PIN28 = 38,
    RASPBERRY_WIRING_PIN29 = 40
} RaspberryWiring;

/**
 * MRAA return codes
 */
typedef enum {
    SUCCESS = 0,                             /**< Expected response */
    ERROR_FEATURE_NOT_IMPLEMENTED = 1,       /**< Feature TODO */
    ERROR_FEATURE_NOT_SUPPORTED = 2,         /**< Feature not supported by HW */
    ERROR_INVALID_VERBOSITY_LEVEL = 3,       /**< Verbosity level wrong */
    ERROR_INVALID_PARAMETER = 4,             /**< Parameter invalid */
    ERROR_INVALID_HANDLE = 5,                /**< Handle invalid */
    ERROR_NO_RESOURCES = 6,                  /**< No resource of that type avail */
    ERROR_INVALID_RESOURCE = 7,              /**< Resource invalid */
    ERROR_INVALID_QUEUE_TYPE = 8,            /**< Queue type incorrect */
    ERROR_NO_DATA_AVAILABLE = 9,             /**< No data available */
    ERROR_INVALID_PLATFORM = 10,             /**< Platform not recognised */
    ERROR_PLATFORM_NOT_INITIALISED = 11,     /**< Board information not initialised */
    ERROR_PLATFORM_ALREADY_INITIALISED = 0,  /**< Board is already initialised, same as SUCCESS */

    ERROR_UNSPECIFIED = 99 /**< Unknown Error */
} Result;

/**
 * Enum representing different possible modes for a pin.
 */
typedef enum {
    PIN_VALID = 0,     /**< Pin Valid */
    PIN_GPIO = 1,      /**< General Purpose IO */
    PIN_PWM = 2,       /**< Pulse Width Modulation */
    PIN_FAST_GPIO = 3, /**< Faster GPIO */
    PIN_SPI = 4,       /**< SPI */
    PIN_I2C = 5,       /**< I2C */
    PIN_AIO = 6,       /**< Analog in */
    PIN_UART = 7       /**< UART */
} Pinmodes;

/**
 * Enum reprensenting different i2c speeds/modes
 */
typedef enum {
    I2C_STD = 0,  /**< up to 100Khz */
    I2C_FAST = 1, /**< up to 400Khz */
    I2C_HIGH = 2  /**< up to 3.4Mhz */
} I2cMode;

typedef enum {
    UART_PARITY_NONE = 0,
    UART_PARITY_EVEN = 1,
    UART_PARITY_ODD = 2,
    UART_PARITY_MARK = 3,
    UART_PARITY_SPACE = 4
} UartParity;

}
<|endoftext|>


<commit_before>#include <stdio.h>
#ifdef WIN32
#include <windows.h>
#endif
#include <GL/glut.h>
#include "raytracing.h"

//temporary variables
Vec3Df testRayOrigin;
Vec3Df testRayDestination;

//use this function for any preprocessing of the mesh.
void init()
{
	//load the mesh file
	//feel free to replace cube by a path to another model
	//please realize that not all OBJ files will successfully load.
	//Nonetheless, if they come from Blender, they should.
	//there is a difference between windows written objs and Linux written objs.
	//hence, some models might not yet work well.
    //MyMesh.loadMesh("cube2.obj", true);

    MyMesh.loadMesh("mesh/monkey.obj", true);

//    MyMesh.loadMesh("cube.obj", true);
	MyMesh.computeVertexNormals();

	//one first move: initialize the first light source
	//at least ONE light source has to be in the scene!!!
	//here, we set it to the current location of the camera
	MyLightPositions.push_back(MyCameraPosition);
}

//return the color of your pixel.
Vec3Df performRayTracing(const Vec3Df & origin, const Vec3Df & dest)
{
	return Vec3Df(1,0,0);
}

void yourDebugDraw()
{
	//draw open gl debug stuff
	//this function is called every frame

	//as an example:
	glPushAttrib(GL_ALL_ATTRIB_BITS);
	glDisable(GL_LIGHTING);
	glColor3f(0,1,1);
	glBegin(GL_LINES);
	glVertex3f(testRayOrigin[0], testRayOrigin[1], testRayOrigin[2]);
	glVertex3f(testRayDestination[0], testRayDestination[1], testRayDestination[2]);
	glEnd();
	glPointSize(10);
	glBegin(GL_POINTS);
	glVertex3fv(MyLightPositions[0].pointer());
	glEnd();
	glPopAttrib();

}

void yourKeyboardFunc(char t, int x, int y)
{
	// do what you want with the keyboard input t.
	// x, y are the screen position

	//here I use it to get the coordinates of a ray, which I then draw in the debug function.
	produceRay(x, y, testRayOrigin, testRayDestination);

	std::cout<<t<<" pressed! The mouse was in location "<<x<<","<<y<<"!"<<std::endl;
}
<commit_msg>formatting :X<commit_after>#include <stdio.h>
#ifdef WIN32
#include <windows.h>
#endif
#include <GL/glut.h>
#include "raytracing.h"

//temporary variables
Vec3Df testRayOrigin;
Vec3Df testRayDestination;

//use this function for any preprocessing of the mesh.
void init(){
    //load the mesh file
    //feel free to replace cube by a path to another model
    //please realize that not all OBJ files will successfully load.
    //Nonetheless, if they come from Blender, they should.
    //there is a difference between windows written objs and Linux written objs.
    //hence, some models might not yet work well.
    //MyMesh.loadMesh("cube2.obj", true);

    MyMesh.loadMesh("mesh/monkey.obj", true);

//    MyMesh.loadMesh("cube.obj", true);
    MyMesh.computeVertexNormals();

    //one first move: initialize the first light source
    //at least ONE light source has to be in the scene!!!
    //here, we set it to the current location of the camera
    MyLightPositions.push_back(MyCameraPosition);
}

//return the color of your pixel.
Vec3Df performRayTracing(const Vec3Df & origin, const Vec3Df & dest){
    return Vec3Df(1, 0, 0);
}

void yourDebugDraw(){
    //draw open gl debug stuff
    //this function is called every frame

    //as an example:
    glPushAttrib(GL_ALL_ATTRIB_BITS);
    glDisable(GL_LIGHTING);
    glColor3f(0, 1, 1);
    glBegin(GL_LINES);
    glVertex3f(testRayOrigin[0], testRayOrigin[1], testRayOrigin[2]);
    glVertex3f(testRayDestination[0], testRayDestination[1],
            testRayDestination[2]);
    glEnd();
    glPointSize(10);
    glBegin(GL_POINTS);
    glVertex3fv(MyLightPositions[0].pointer());
    glEnd();
    glPopAttrib();

}

void yourKeyboardFunc(char t, int x, int y){
    // do what you want with the keyboard input t.
    // x, y are the screen position

    //here I use it to get the coordinates of a ray, which I then draw in the debug function.
    produceRay(x, y, testRayOrigin, testRayDestination);

    std::cout << t << " pressed! The mouse was in location " << x << "," << y
            << "!" << std::endl;
}
<|endoftext|>


<commit_before>// Copyright (c) 2011-2014 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <qt/guiutil.h>
#include <qt/transactiondescdialog.h>
#include <qt/forms/ui_transactiondescdialog.h>

#include <qt/transactiontablemodel.h>

#include <QModelIndex>
#include <QSettings>
#include <QString>

TransactionDescDialog::TransactionDescDialog(const QModelIndex &idx, QWidget *parent) :
    QDialog(parent),
    ui(new Ui::TransactionDescDialog)
{
    ui->setupUi(this);
    setWindowTitle(tr("Details for %1").arg(idx.data(TransactionTableModel::TxIDRole).toString()));
    QString desc = idx.data(TransactionTableModel::LongDescriptionRole).toString();
    ui->detailText->setHtml(desc);
}

TransactionDescDialog::~TransactionDescDialog()
{
    delete ui;
}
<commit_msg>qt: Make sure font size in  TransactionDescDialog is adjusted properly (#3707)<commit_after>// Copyright (c) 2011-2014 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <qt/guiutil.h>
#include <qt/transactiondescdialog.h>
#include <qt/forms/ui_transactiondescdialog.h>

#include <qt/transactiontablemodel.h>

#include <QModelIndex>
#include <QSettings>
#include <QString>

TransactionDescDialog::TransactionDescDialog(const QModelIndex &idx, QWidget *parent) :
    QDialog(parent),
    ui(new Ui::TransactionDescDialog)
{
    ui->setupUi(this);
    GUIUtil::updateFonts();
    setWindowTitle(tr("Details for %1").arg(idx.data(TransactionTableModel::TxIDRole).toString()));
    QString desc = idx.data(TransactionTableModel::LongDescriptionRole).toString();
    ui->detailText->setHtml(desc);
}

TransactionDescDialog::~TransactionDescDialog()
{
    delete ui;
}
<|endoftext|>