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_bubble_view.h" | 5 #include "ash/system/tray/tray_bubble_view.h" |
6 | 6 |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "ash/shell_window_ids.h" | 8 #include "ash/shell_window_ids.h" |
9 #include "ash/system/tray/tray_constants.h" | 9 #include "ash/system/tray/tray_constants.h" |
10 #include "ash/wm/shelf_layout_manager.h" | 10 #include "ash/wm/shelf_layout_manager.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 : views::BubbleBorder(arrow_location, | 73 : views::BubbleBorder(arrow_location, |
74 views::BubbleBorder::NO_SHADOW), | 74 views::BubbleBorder::NO_SHADOW), |
75 owner_(owner), | 75 owner_(owner), |
76 tray_arrow_offset_(arrow_offset) { | 76 tray_arrow_offset_(arrow_offset) { |
77 set_alignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); | 77 set_alignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); |
78 } | 78 } |
79 | 79 |
80 virtual ~TrayBubbleBorder() {} | 80 virtual ~TrayBubbleBorder() {} |
81 | 81 |
82 private: | 82 private: |
| 83 views::Background* FindAppropriateBackground(views::View* view, |
| 84 const gfx::Point& point) const { |
| 85 views::Background* background = NULL; |
| 86 views::View* target = view->GetEventHandlerForPoint(point); |
| 87 for (; target && !background; target = target->parent()) |
| 88 background = target->background(); |
| 89 return background; |
| 90 } |
| 91 |
83 // Overridden from views::BubbleBorder. | 92 // Overridden from views::BubbleBorder. |
84 // Override views::BubbleBorder to set the bubble on top of the anchor when | 93 // Override views::BubbleBorder to set the bubble on top of the anchor when |
85 // it has no arrow. | 94 // it has no arrow. |
86 virtual gfx::Rect GetBounds(const gfx::Rect& position_relative_to, | 95 virtual gfx::Rect GetBounds(const gfx::Rect& position_relative_to, |
87 const gfx::Size& contents_size) const OVERRIDE { | 96 const gfx::Size& contents_size) const OVERRIDE { |
88 if (arrow_location() != NONE) { | 97 if (arrow_location() != NONE) { |
89 return views::BubbleBorder::GetBounds(position_relative_to, | 98 return views::BubbleBorder::GetBounds(position_relative_to, |
90 contents_size); | 99 contents_size); |
91 } | 100 } |
92 | 101 |
(...skipping 21 matching lines...) Expand all Loading... |
114 | 123 |
115 // Draw the bottom line. | 124 // Draw the bottom line. |
116 int y = owner_->height() + inset.top(); | 125 int y = owner_->height() + inset.top(); |
117 canvas->FillRect(gfx::Rect(inset.left(), y, owner_->width(), | 126 canvas->FillRect(gfx::Rect(inset.left(), y, owner_->width(), |
118 kBottomLineHeight), kBorderDarkColor); | 127 kBottomLineHeight), kBorderDarkColor); |
119 | 128 |
120 if (!Shell::GetInstance()->shelf()->IsVisible() || | 129 if (!Shell::GetInstance()->shelf()->IsVisible() || |
121 arrow_location() == views::BubbleBorder::NONE) | 130 arrow_location() == views::BubbleBorder::NONE) |
122 return; | 131 return; |
123 | 132 |
| 133 gfx::Point arrow_reference; |
| 134 |
124 // Draw the arrow after drawing child borders, so that the arrow can cover | 135 // Draw the arrow after drawing child borders, so that the arrow can cover |
125 // the its overlap section with child border. | 136 // the its overlap section with child border. |
126 SkPath path; | 137 SkPath path; |
127 path.incReserve(4); | 138 path.incReserve(4); |
128 if (arrow_location() == views::BubbleBorder::BOTTOM_RIGHT) { | 139 if (arrow_location() == views::BubbleBorder::BOTTOM_RIGHT) { |
129 int tip_x = base::i18n::IsRTL() ? tray_arrow_offset_ : | 140 int tip_x = base::i18n::IsRTL() ? tray_arrow_offset_ : |
130 owner_->width() - tray_arrow_offset_; | 141 owner_->width() - tray_arrow_offset_; |
131 tip_x = std::min(std::max(kArrowMinOffset, tip_x), | 142 tip_x = std::min(std::max(kArrowMinOffset, tip_x), |
132 owner_->width() - kArrowMinOffset); | 143 owner_->width() - kArrowMinOffset); |
133 int left_base_x = tip_x - kArrowWidth / 2; | 144 int left_base_x = tip_x - kArrowWidth / 2; |
134 int left_base_y = y; | 145 int left_base_y = y; |
135 int tip_y = left_base_y + kArrowHeight; | 146 int tip_y = left_base_y + kArrowHeight; |
136 path.moveTo(SkIntToScalar(left_base_x), SkIntToScalar(left_base_y)); | 147 path.moveTo(SkIntToScalar(left_base_x), SkIntToScalar(left_base_y)); |
137 path.lineTo(SkIntToScalar(tip_x), SkIntToScalar(tip_y)); | 148 path.lineTo(SkIntToScalar(tip_x), SkIntToScalar(tip_y)); |
138 path.lineTo(SkIntToScalar(left_base_x + kArrowWidth), | 149 path.lineTo(SkIntToScalar(left_base_x + kArrowWidth), |
139 SkIntToScalar(left_base_y)); | 150 SkIntToScalar(left_base_y)); |
| 151 arrow_reference.SetPoint(tip_x, left_base_y - kArrowHeight); |
140 } else { | 152 } else { |
141 int tip_y = y - tray_arrow_offset_; | 153 int tip_y = y - tray_arrow_offset_; |
142 tip_y = std::min(std::max(kArrowMinOffset, tip_y), | 154 tip_y = std::min(std::max(kArrowMinOffset, tip_y), |
143 owner_->height() - kArrowMinOffset); | 155 owner_->height() - kArrowMinOffset); |
144 int top_base_y = tip_y - kArrowWidth / 2; | 156 int top_base_y = tip_y - kArrowWidth / 2; |
145 int top_base_x, tip_x; | 157 int top_base_x, tip_x; |
146 if (arrow_location() == views::BubbleBorder::LEFT_BOTTOM) { | 158 if (arrow_location() == views::BubbleBorder::LEFT_BOTTOM) { |
147 top_base_x = inset.left() + kSystemTrayBubbleHorizontalInset; | 159 top_base_x = inset.left() + kSystemTrayBubbleHorizontalInset; |
148 tip_x = top_base_x - kArrowHeight; | 160 tip_x = top_base_x - kArrowHeight; |
| 161 arrow_reference.SetPoint(top_base_x + kArrowHeight, tip_y); |
149 } else { | 162 } else { |
150 DCHECK(arrow_location() == views::BubbleBorder::RIGHT_BOTTOM); | 163 DCHECK(arrow_location() == views::BubbleBorder::RIGHT_BOTTOM); |
151 top_base_x = inset.left() + owner_->width() - | 164 top_base_x = inset.left() + owner_->width() - |
152 kSystemTrayBubbleHorizontalInset; | 165 kSystemTrayBubbleHorizontalInset; |
153 tip_x = top_base_x + kArrowHeight; | 166 tip_x = top_base_x + kArrowHeight; |
| 167 arrow_reference.SetPoint(top_base_x - kArrowHeight, tip_y); |
154 } | 168 } |
155 path.moveTo(SkIntToScalar(top_base_x), SkIntToScalar(top_base_y)); | 169 path.moveTo(SkIntToScalar(top_base_x), SkIntToScalar(top_base_y)); |
156 path.lineTo(SkIntToScalar(tip_x), SkIntToScalar(tip_y)); | 170 path.lineTo(SkIntToScalar(tip_x), SkIntToScalar(tip_y)); |
157 path.lineTo(SkIntToScalar(top_base_x), | 171 path.lineTo(SkIntToScalar(top_base_x), |
158 SkIntToScalar(top_base_y + kArrowWidth)); | 172 SkIntToScalar(top_base_y + kArrowWidth)); |
159 } | 173 } |
160 | 174 |
| 175 views::Background* background = FindAppropriateBackground(owner_, |
| 176 arrow_reference); |
| 177 |
161 SkPaint paint; | 178 SkPaint paint; |
162 paint.setStyle(SkPaint::kFill_Style); | 179 paint.setStyle(SkPaint::kFill_Style); |
163 paint.setColor(kHeaderBackgroundColorDark); | 180 paint.setColor(background ? background->get_color() : kBackgroundColor); |
164 canvas->DrawPath(path, paint); | 181 canvas->DrawPath(path, paint); |
165 | 182 |
166 // Now draw the arrow border. | 183 // Now draw the arrow border. |
167 paint.setStyle(SkPaint::kStroke_Style); | 184 paint.setStyle(SkPaint::kStroke_Style); |
168 paint.setColor(kBorderDarkColor); | 185 paint.setColor(kBorderDarkColor); |
169 canvas->DrawPath(path, paint); | 186 canvas->DrawPath(path, paint); |
170 | 187 |
171 } | 188 } |
172 | 189 |
173 views::View* owner_; | 190 views::View* owner_; |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 views::View* child) { | 312 views::View* child) { |
296 if (is_add && child == this) { | 313 if (is_add && child == this) { |
297 parent->SetPaintToLayer(true); | 314 parent->SetPaintToLayer(true); |
298 parent->SetFillsBoundsOpaquely(true); | 315 parent->SetFillsBoundsOpaquely(true); |
299 parent->layer()->SetMasksToBounds(true); | 316 parent->layer()->SetMasksToBounds(true); |
300 } | 317 } |
301 } | 318 } |
302 | 319 |
303 } // namespace internal | 320 } // namespace internal |
304 } // namespace ash | 321 } // namespace ash |
OLD | NEW |