summaryrefslogtreecommitdiffstats
path: root/chrome/views
diff options
context:
space:
mode:
authormunjal@chromium.org <munjal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-13 01:46:20 +0000
committermunjal@chromium.org <munjal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-13 01:46:20 +0000
commitd185b2fd15adfee5cad70656545d66440c6b2113 (patch)
tree51bfde5ee14df3dac48076f2dbbd686d1a3fcc54 /chrome/views
parentb15226c12d04b2fb6ceee6f5ec2a5b2dd4aaff3b (diff)
downloadchromium_src-d185b2fd15adfee5cad70656545d66440c6b2113.zip
chromium_src-d185b2fd15adfee5cad70656545d66440c6b2113.tar.gz
chromium_src-d185b2fd15adfee5cad70656545d66440c6b2113.tar.bz2
Add ability to set a flag in the Label view class that tells it to
return a preferred size of 0, 0 when the label is not visible. Review URL: http://codereview.chromium.org/21313 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@9725 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/views')
-rw-r--r--chrome/views/label.cc10
-rw-r--r--chrome/views/label.h10
-rw-r--r--chrome/views/link.h2
3 files changed, 22 insertions, 0 deletions
diff --git a/chrome/views/label.cc b/chrome/views/label.cc
index bd9ddf61..f0c38d8 100644
--- a/chrome/views/label.cc
+++ b/chrome/views/label.cc
@@ -44,6 +44,7 @@ void Label::Init(const std::wstring& text, const ChromeFont& font) {
color_ = kEnabledColor;
horiz_alignment_ = ALIGN_CENTER;
is_multi_line_ = false;
+ collapse_when_hidden_ = false;
}
Label::~Label() {
@@ -51,6 +52,15 @@ Label::~Label() {
gfx::Size Label::GetPreferredSize() {
gfx::Size prefsize;
+
+ // Return a size of (0, 0) if the label is not visible and if the
+ // collapse_when_hidden_ flag is set.
+ // TODO(munjal): This logic probably belongs to the View class. But for now,
+ // put it here since putting it in View class means all inheriting classes
+ // need ot respect the collapse_when_hidden_ flag.
+ if (!IsVisible() && collapse_when_hidden_)
+ return prefsize;
+
if (is_multi_line_) {
int w = width(), h = 0;
ChromeCanvas::SizeStringInt(text_, font_, &w, &h, ComputeMultiLineFlags());
diff --git a/chrome/views/label.h b/chrome/views/label.h
index 385518d..84e685c 100644
--- a/chrome/views/label.h
+++ b/chrome/views/label.h
@@ -143,6 +143,12 @@ class Label : public View {
virtual bool GetAccessibleState(VARIANT* state);
#endif // defined(OS_WIN)
+ // Gets/sets the flag to determine whether the label should be collapsed when
+ // it's hidden (not visible). If this flag is true, the label will return a
+ // preferred size of (0, 0) when it's not visible.
+ void set_collapse_when_hidden(bool value) { collapse_when_hidden_ = value; }
+ bool collapse_when_hidden() const { return collapse_when_hidden_; }
+
private:
// These tests call CalculateDrawStringParams in order to verify the
// calculations done for drawing text.
@@ -184,6 +190,10 @@ class Label : public View {
// Whether the mouse is over this label.
bool contains_mouse_;
scoped_ptr<Background> mouse_over_background_;
+ // Whether to collapse the label when it's not visible.
+ bool collapse_when_hidden_;
+
+ DISALLOW_COPY_AND_ASSIGN(Label);
};
} // namespace views
diff --git a/chrome/views/link.h b/chrome/views/link.h
index e80b1795..87d7d85 100644
--- a/chrome/views/link.h
+++ b/chrome/views/link.h
@@ -85,6 +85,8 @@ class Link : public Label {
// The color when the link is neither highlighted nor disabled.
SkColor normal_color_;
+
+ DISALLOW_COPY_AND_ASSIGN(Link);
};
} // namespace views