OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ash/system/tray/tray_views.h" | 5 #include "ash/system/tray/tray_views.h" |
6 | 6 |
7 #include "ash/system/tray/tray_constants.h" | 7 #include "ash/system/tray/tray_constants.h" |
8 #include "grit/ash_strings.h" | 8 #include "grit/ash_strings.h" |
9 #include "grit/ui_resources.h" | 9 #include "grit/ui_resources.h" |
10 #include "ui/base/accessibility/accessible_view_state.h" | 10 #include "ui/base/accessibility/accessible_view_state.h" |
11 #include "ui/base/resource/resource_bundle.h" | 11 #include "ui/base/resource/resource_bundle.h" |
12 #include "ui/gfx/canvas.h" | 12 #include "ui/gfx/canvas.h" |
13 #include "ui/gfx/image/image.h" | 13 #include "ui/gfx/image/image.h" |
14 #include "ui/gfx/image/image_skia.h" | 14 #include "ui/gfx/image/image_skia.h" |
15 #include "ui/views/border.h" | 15 #include "ui/views/border.h" |
16 #include "ui/views/controls/button/image_button.h" | 16 #include "ui/views/controls/button/image_button.h" |
17 #include "ui/views/controls/label.h" | 17 #include "ui/views/controls/label.h" |
18 #include "ui/views/layout/box_layout.h" | 18 #include "ui/views/layout/box_layout.h" |
19 #include "ui/views/layout/fill_layout.h" | 19 #include "ui/views/layout/fill_layout.h" |
20 #include "ui/views/layout/grid_layout.h" | 20 #include "ui/views/layout/grid_layout.h" |
21 #include "ui/views/painter.h" | 21 #include "ui/views/painter.h" |
22 | 22 |
23 namespace ash { | 23 namespace ash { |
24 namespace internal { | 24 namespace internal { |
25 | 25 |
26 namespace { | 26 namespace { |
27 const int kIconPaddingLeft = 5; | 27 const int kIconPaddingLeft = 5; |
28 const int kPaddingAroundButtons = 5; | 28 const int kPaddingAroundButtons = 5; |
29 | 29 |
30 const int kBarImagesActive[] = { | |
31 IDR_AURA_UBER_TRAY_BAR_BUTTON_ACTIVE_LEFT, | |
32 IDR_AURA_UBER_TRAY_BAR_BUTTON_ACTIVE_CENTER, | |
33 IDR_AURA_UBER_TRAY_BAR_BUTTON_ACTIVE_RIGHT, | |
34 }; | |
35 | |
36 const int kBarImagesDisabled[] = { | |
37 IDR_AURA_UBER_TRAY_BAR_BUTTON_DISABLED_LEFT, | |
38 IDR_AURA_UBER_TRAY_BAR_BUTTON_DISABLED_CENTER, | |
39 IDR_AURA_UBER_TRAY_BAR_BUTTON_DISABLED_RIGHT, | |
40 }; | |
41 | |
30 views::View* CreatePopupHeaderButtonsContainer() { | 42 views::View* CreatePopupHeaderButtonsContainer() { |
31 views::View* view = new views::View; | 43 views::View* view = new views::View; |
32 view->SetLayoutManager(new | 44 view->SetLayoutManager(new |
33 views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, -1)); | 45 views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, -1)); |
34 view->set_border(views::Border::CreateEmptyBorder(0, 0, 0, 5)); | 46 view->set_border(views::Border::CreateEmptyBorder(0, 0, 0, 5)); |
35 return view; | 47 return view; |
36 } | 48 } |
37 | 49 |
38 const int kBorderHeight = 3; | 50 const int kBorderHeight = 3; |
39 const SkColor kBorderGradientDark = SkColorSetRGB(0xae, 0xae, 0xae); | 51 const SkColor kBorderGradientDark = SkColorSetRGB(0xae, 0xae, 0xae); |
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
423 canvas->DrawRect(gfx::Rect(2, 1, width() - 4, height() - 3), | 435 canvas->DrawRect(gfx::Rect(2, 1, width() - 4, height() - 3), |
424 kFocusBorderColor); | 436 kFocusBorderColor); |
425 } | 437 } |
426 } | 438 } |
427 | 439 |
428 void TrayPopupHeaderButton::StateChanged() { | 440 void TrayPopupHeaderButton::StateChanged() { |
429 SchedulePaint(); | 441 SchedulePaint(); |
430 } | 442 } |
431 | 443 |
432 //////////////////////////////////////////////////////////////////////////////// | 444 //////////////////////////////////////////////////////////////////////////////// |
445 // TrayBarButtonWithTitle | |
446 | |
447 class TrayBarButtonWithTitle::TrayBarButton | |
448 : public views::View { | |
449 public: | |
450 TrayBarButton(const int bar_active_images[], const int bar_disabled_images[]) | |
451 : views::View(), | |
452 bar_active_images_(bar_active_images), | |
453 bar_disabled_images_(bar_disabled_images), | |
454 painter_(new views::HorizontalPainter(bar_active_images_)){ | |
455 } | |
456 virtual ~TrayBarButton() {} | |
457 | |
458 // Overriden from views::View | |
459 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { | |
460 painter_->Paint(canvas, size()); | |
461 } | |
462 | |
463 void Update(bool control_on) { | |
464 painter_.reset(new views::HorizontalPainter( | |
465 control_on ? bar_active_images_ : bar_disabled_images_)); | |
466 SchedulePaint(); | |
467 } | |
468 | |
469 private: | |
470 const int* bar_active_images_; | |
471 const int* bar_disabled_images_; | |
472 scoped_ptr<views::HorizontalPainter> painter_; | |
473 | |
474 DISALLOW_COPY_AND_ASSIGN(TrayBarButton); | |
475 }; | |
476 | |
477 TrayBarButtonWithTitle::TrayBarButtonWithTitle(views::ButtonListener* listener, | |
478 int title_id, | |
479 int width) | |
480 : views::CustomButton(listener), | |
481 image_(new TrayBarButton(kBarImagesActive, kBarImagesDisabled)), | |
482 title_(new views::Label), | |
483 width_(width) { | |
484 AddChildView(image_); | |
485 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
486 string16 text = rb.GetLocalizedString(title_id); | |
487 title_->SetText(text); | |
488 AddChildView(title_); | |
489 | |
490 image_height_ = ui::ResourceBundle::GetSharedInstance().GetImageNamed( | |
491 kBarImagesActive[0]).ToImageSkia()->height(); | |
492 } | |
493 | |
494 TrayBarButtonWithTitle::~TrayBarButtonWithTitle() {} | |
495 | |
496 gfx::Size TrayBarButtonWithTitle::GetPreferredSize() { | |
497 return gfx::Size(width_, kTrayPopupItemHeight); | |
498 } | |
499 | |
500 void TrayBarButtonWithTitle::Layout() { | |
501 gfx::Size title_size = title_->GetPreferredSize(); | |
502 gfx::Rect rect(GetContentsBounds()); | |
503 int bar_image_y = rect.height() / 2 - image_height_ / 2; | |
504 gfx::Rect bar_image_rect(rect.x(), | |
505 bar_image_y, | |
506 rect.width(), | |
507 image_height_); | |
508 image_->SetBoundsRect(bar_image_rect); | |
509 // The image_ has some empty space below the bar image, move the title | |
510 // a little bit up to look closer to the bar. | |
511 title_->SetBounds(rect.x(), | |
512 bar_image_y + image_height_ - 3, | |
513 rect.width(), | |
sadrul
2012/07/23 21:02:30
Instead of doing this, could there be a box-layout
jennyz
2012/07/23 21:22:03
It seems more flexible to control the layout by pr
| |
514 title_size.height()); | |
515 } | |
516 | |
517 void TrayBarButtonWithTitle::UpdateButton(bool control_on) { | |
518 image_->Update(control_on); | |
519 } | |
520 | |
521 //////////////////////////////////////////////////////////////////////////////// | |
433 // SpecialPopupRow | 522 // SpecialPopupRow |
434 | 523 |
435 SpecialPopupRow::SpecialPopupRow() | 524 SpecialPopupRow::SpecialPopupRow() |
436 : content_(NULL), | 525 : content_(NULL), |
437 button_container_(NULL) { | 526 button_container_(NULL) { |
438 views::Background* background = views::Background::CreateBackgroundPainter( | 527 views::Background* background = views::Background::CreateBackgroundPainter( |
439 true, views::Painter::CreateVerticalGradient(kHeaderBackgroundColorLight, | 528 true, views::Painter::CreateVerticalGradient(kHeaderBackgroundColorLight, |
440 kHeaderBackgroundColorDark)); | 529 kHeaderBackgroundColorDark)); |
441 background->SetNativeControlColor(kHeaderBackgroundColorDark); | 530 background->SetNativeControlColor(kHeaderBackgroundColorDark); |
442 set_background(background); | 531 set_background(background); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
519 label->SetAutoColorReadabilityEnabled(false); | 608 label->SetAutoColorReadabilityEnabled(false); |
520 label->SetEnabledColor(SK_ColorWHITE); | 609 label->SetEnabledColor(SK_ColorWHITE); |
521 label->SetBackgroundColor(SkColorSetARGB(0, 255, 255, 255)); | 610 label->SetBackgroundColor(SkColorSetARGB(0, 255, 255, 255)); |
522 label->SetShadowColors(SkColorSetARGB(64, 0, 0, 0), | 611 label->SetShadowColors(SkColorSetARGB(64, 0, 0, 0), |
523 SkColorSetARGB(64, 0, 0, 0)); | 612 SkColorSetARGB(64, 0, 0, 0)); |
524 label->SetShadowOffset(0, 1); | 613 label->SetShadowOffset(0, 1); |
525 } | 614 } |
526 | 615 |
527 } // namespace internal | 616 } // namespace internal |
528 } // namespace ash | 617 } // namespace ash |
OLD | NEW |