summaryrefslogtreecommitdiffstats
path: root/views/controls/native_control_gtk.cc
blob: 5576f2964af611ba5ad3dddf1becac59fb648618 (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
// #ifndef CHROME_VIEWS_NATIVE_CONTROL_WIN_H_// 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 "views/controls/native_control_gtk.h"

#include <gtk/gtk.h>

#include "base/logging.h"

namespace views {

NativeControlGtk::NativeControlGtk() {
}

NativeControlGtk::~NativeControlGtk() {
  if (native_view())
    gtk_widget_destroy(native_view());
}

////////////////////////////////////////////////////////////////////////////////
// NativeControlGtk, View overrides:

void NativeControlGtk::SetEnabled(bool enabled) {
  NOTIMPLEMENTED();
  if (IsEnabled() != enabled) {
    View::SetEnabled(enabled);
    if (native_view())
      gtk_widget_set_sensitive(native_view(), IsEnabled());
  }
}

void NativeControlGtk::ViewHierarchyChanged(bool is_add, View* parent,
                                            View* child) {
  // Call the base class to hide the view if we're being removed.
  NativeViewHost::ViewHierarchyChanged(is_add, parent, child);

  // Create the widget when we're added to a valid Widget. Many controls need a
  // parent widget to function properly.
  if (is_add && GetWidget() && !native_view())
    CreateNativeControl();
}

void NativeControlGtk::VisibilityChanged(View* starting_from, bool is_visible) {
  if (!is_visible) {
    // We destroy the child widget when we become invisible because of the
    // performance cost of maintaining widgets that aren't currently needed.
    GtkWidget* widget = native_view();
    Detach();
    gtk_widget_destroy(widget);
  } else if (!native_view()) {
    CreateNativeControl();
  }
}

void NativeControlGtk::Focus() {
  DCHECK(native_view());
  NOTIMPLEMENTED();
}

void NativeControlGtk::NativeControlCreated(GtkWidget* native_control) {
  Attach(native_control);

  // Update the newly created GtkWdigetwith any resident enabled state.
  gtk_widget_set_sensitive(native_view(), IsEnabled());
}

}  // namespace views