summaryrefslogtreecommitdiffstats
path: root/chrome/browser/gtk/status_bubble_gtk.cc
blob: dc4ca24730db9634e7b377a5660548e7fa3543ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// 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/status_bubble_gtk.h"

#include "base/string_util.h"
#include "googleurl/src/gurl.h"

// NOTE: this code is probably the wrong approach for the status bubble.
// Talk to evanm before you attempt to fix bugs in it -- we're probably
// better off restructuring it.

StatusBubbleGtk::StatusBubbleGtk(GtkWindow* parent)
    : parent_(parent), window_(NULL) {
}

StatusBubbleGtk::~StatusBubbleGtk() {
  Hide();
}

void StatusBubbleGtk::SetStatus(const std::string& status) {
  if (status.empty()) {
    Hide();
    return;
  }

  if (!window_)
    Create();

  gtk_label_set_text(GTK_LABEL(label_), status.c_str());
  Reposition();
  gtk_widget_show(window_);
}

void StatusBubbleGtk::SetStatus(const std::wstring& status) {
  SetStatus(WideToUTF8(status));
}

void StatusBubbleGtk::SetURL(const GURL& url, const std::wstring& languages) {
  SetStatus(url.spec());
}

void StatusBubbleGtk::Hide() {
  if (!window_)
    return;
  gtk_widget_destroy(window_);
  window_ = NULL;
}

void StatusBubbleGtk::MouseMoved() {
  if (!window_)
    return;
  // We ignore for now.
  // TODO(port): the fancy sliding behavior.
}

void StatusBubbleGtk::Create() {
  if (window_)
    return;

  window_ = gtk_window_new(GTK_WINDOW_POPUP);
  gtk_window_set_transient_for(GTK_WINDOW(window_), parent_);
  gtk_container_set_border_width(GTK_CONTAINER(window_), 2);
  label_ = gtk_label_new("");
  gtk_widget_show(label_);
  gtk_container_add(GTK_CONTAINER(window_), label_);
}

void StatusBubbleGtk::Reposition() {
  int x, y, width, parent_height;
  gdk_window_get_position(GTK_WIDGET(parent_)->window, &x, &y);
  gtk_window_get_size(parent_, &width, &parent_height);
  GtkRequisition requisition;
  gtk_widget_size_request(window_, &requisition);
  // TODO(port): RTL positioning.
  gtk_window_move(GTK_WINDOW(window_), x,
                  y + parent_height - requisition.height);
}